• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

PHP Includes question

apreichner

New Member
I have been taking a long break from the web design world, and I'm anxious to come back, but there is just something I can't quite remember.

When I used to make web pages I used to use PHP to keep my navigation the same throughout every page. I've tried googling it to refresh my memory, but all of the pages I have found seem to be using a different method than I did.

I only used one index.php page and my content pages were generally just basic .txt files with minor HTML commands (Bold, Italics, Etc. - No Header or Body commands). And some how I was able to just set my links on my index.php page to index.php?=content (or something like that, I can't really remember exactly.)

If anyone could refresh my memory on how I did that, it would be greatly appreciated. It's been so long!
 
Actually, I found what I was looking for... I'll show you how I did it.

<?php
$page = $_GET['page']; /* gets the variable $page */
if (!empty($page)) {
include($page);
} /* if $page has a value, include it */
else {
include('page1.txt');
} /* otherwise, include the default page */
?>

so the url to a link on there would be:

<a href="index.php?page=page1.txt">page 1</a>

or whatever, I don't think the extension matters. But the layout would be the index.php page and I would just put that code into the content section. And each content page would be one of those .txt files with basic html tags.
 
For security reasons, it would be much better to have an array of all the "allowed" files and have the index script check the URL value against the array. Otherwise someone can include any file on your server that your username has access to. Depending on server settings, someone could include any file on the web.

An example is included below:
PHP:
<?php
$pages = array('page1','page2','etc');
if (in_array($_GET['page'],$pages)) {
	include($_GET['page'].'.txt');
} else {
	include('page1.txt');
}
?>
 
I realize they just updated the php, but I wonder why I am getting 500 errors for a page that is set at 755 the page has a included header and footer both set at 755..

This is really suck, I guess I can say to heck with php and go back to ssi or perl ...

-Amanita
 
Back
Top