Help - Search - Members - Calendar
Full Version: A Little Bit Of Guidance...
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
Earpy
Hey guys,

I am looking for a little bit of support. My current aim is to have a script which will call a page and add it to a template. For example, I have a page called page1.html and that page only contains html, which I then want to include into the template by typing in http://www.somedomain.com/index.php?page=page1.html. If the page exists, it will include it, otherwise it will redirect to a error page. Anybody give me some tips, or even better a script which would do this? (Sorry if i sound as if I am stealing scripts)

Thanks in advance for any help,
Earpy
MrTouz
i have that script... problem is its implanted inside PHPBB3 ive been trying to take it off to make it work inside a simple site...

example of what it does : http://www.allroundelites.com/community/page.php?page=home

you dont need to put the .html behind the page=

only problem with my script is that i dont have a else { so if you give a wrong url it just makes somthing ugly.

Ill try once more tonight to take this code out and past it here if anyone is whilling to correct it for you ?
Alex
What I would recommend is a switch like the following:

CODE
<?php
switch($_GET['page'])
{
   case 'home':
      echo file_get_contents('home.html');
      break;
   case 'work':
      echo file_get_contents('portfolio.html');
      break;
   default:
      echo file_get_contents('error.html');
}
?>


You add a case for each entry, which means that you can easily make the URL and filename different (as shown in this example ?page=work included portfolio.html), if none of the cases match it does the default which is an error page. It's good for those of us with paranoia as well, because since we explicitly include each page with hardlinks it's not possible to sneak in some user input which would cause us to include a remote page.

References:
http://php.net/switch
http://php.net/include_once
Earpy
Thanks, both of you, for your replies. Your help is much apperciated smile.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.