Page 1 of 1

PHP include

Posted: Fri Sep 18, 2009 7:28 pm
by bertsquall
Hi, first time post as i am new to php so at the moment sticking to the basics. I set up a web page recently so it would work in the way i would have one design so when i click a link it brings the seperate html file into the main content of the page which i have called index.php . Where i want each html file to be brought into the index php i have put the following code:

<?php
if($page) include("$page.html");
else include("home.html");
?>

So when a link is clicked essentially the the link will go into the part of the index.php i want. However, each time i click the link it always brings up my home. html. I have linked them so they should call files such as the news.html. I use :

http://www.apexstudioss.com/index.php?page=news
for the news page

http://www.apexstudioss.com/index.php?page=home
for the home page

http://www.apexstudioss.com/index.php?p ... s_projects
for the project page

but it always come up with the home page regardless of what i do. Can anyone help

Thanks in advance bertsquall.

Re: PHP include

Posted: Fri Sep 18, 2009 7:36 pm
by jackpf
Ok...
1. Don't you mean $_GET['page']? You shouldn't use register globals (if you are doing so)
2. You should use basename() on $_GET['page'] to make sure people don't hack you...
3. You should probably check the file exists before trying to include it



:)