HostRiot
09-22-2002, 04:50 AM
What would be the code for a index.php to have content in the middle of the page(text, images, etc...), but when a link is click(lets say services) it runs index.php?page=services, and it replaces the content that was in the middle. I know how to do this when your already on a ?page=BLAH, but I do not know how to make it so the default content on the index.php gets replaced...
Anyone know the answer?
Xandra
09-22-2002, 07:32 AM
This should work:
<?php
if(is_file("$page.php"))
{
include("$page.php");
}
else
{
include("default.php");
}
?>
JustinH
09-22-2002, 02:15 PM
In a recent post we went through this too... But MAKE SURE you do error checking so that an important file isn't included:
if (preg_match("/\W/")) {
include("default.php");
}
This way if the user changes $page and uses ../../someuser/sql.conf it'll only include the default page (\W matches any character that is not alphanumeric or an underscore).
phpcoder
09-22-2002, 03:29 PM
<HTML>
<TITLE>Home</TITLE>
<HEAD>
</HEAD>
<BODY>
<?php
if(empty($page)) {
include "index2.html";
} else {
include "$page.html";
}
?>
</BODY>
</HTML>
mattschinkel
09-23-2002, 11:20 PM
Yes, I used these methods on my web page.... check it out....
:D
michaeln
09-23-2002, 11:50 PM
If I might give a suggestion.
when you make your template page that will insert the content page into the middle put it in a non web directory..
Then put each page in its own folder.
I.E. The only page in http://www.mydomain.com/ is your home page. Then put your plans page in http://www.mydomain.com/plans
etc etc etc.
This is done by creating a index.php file in each directory. That index.php file sets the variable page and any other variables you may want to pre define for that particular page, IE dynamic menues etc. After it sets the variables it does a require() to your template page in the non web directory.
This does a few more things for you.
(1) It gives you more control over what you can do. Like with the dynamic menus in the template.
(2) It makes the URLs easy for users to cut, paste and share with their friends which is always a good thing.
(3) The users never see anything like ?page=whatever etc.
Regards,
Michael
Rich2k
09-24-2002, 04:19 AM
Please, please, please call page as $_GET['page'] though as opposed to $page.
You may find that the latter method doesn't work on all servers as it's been disabled.