Results 1 to 7 of 7
Thread: Simple PHP question...
-
09-22-2002, 04:50 AM #1Disabled
- Join Date
- Sep 2002
- Location
- http://www.hostriot.com
- Posts
- 135
Simple PHP question...
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?
-
09-22-2002, 07:32 AM #2Junior Guru Wannabe
- Join Date
- Sep 2002
- Posts
- 96
This should work:
Code:<?php if(is_file("$page.php")) { include("$page.php"); } else { include("default.php"); } ?>
Last edited by Xandra; 09-22-2002 at 12:11 PM.
-
09-22-2002, 02:15 PM #3Web Hosting Master
- Join Date
- Nov 2000
- Posts
- 3,046
In a recent post we went through this too... But MAKE SURE you do error checking so that an important file isn't included:
Code:if (preg_match("/\W/")) { include("default.php"); }
A well-reasoned assumption is very close to fact.
- Adorno
-
09-22-2002, 03:29 PM #4Web Hosting Master
- Join Date
- Apr 2002
- Location
- Philadelphia
- Posts
- 2,278
PHP Code:<HTML>
<TITLE>Home</TITLE>
<HEAD>
</HEAD>
<BODY>
<?php
if(empty($page)) {
include "index2.html";
} else {
include "$page.html";
}
?>
</BODY>
</HTML>Last edited by phpcoder; 09-22-2002 at 03:39 PM.
-
09-23-2002, 11:20 PM #5Web Hosting Guru
- Join Date
- Aug 2002
- Location
- Toronto, Canada
- Posts
- 286
Yes, I used these methods on my web page.... check it out....
www.prolinker.com - free automatic linking to your website
-
09-23-2002, 11:50 PM #6Web Hosting Master
- Join Date
- Nov 2001
- Posts
- 857
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<?
header("Location: http://www.hostevolve.com/");
?>
-
09-24-2002, 04:19 AM #7Web Hosting Master
- Join Date
- May 2002
- Location
- UK
- Posts
- 2,997
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.