PDA

View Full Version : PHP Includes question



apreichner
July 7th, 2009, 18:46
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!

Dynash
July 7th, 2009, 19:30
Does this help you? http://corz.org/serv/tricks/htaccess2.php Basically tells you how to do it.

bariteau
July 7th, 2009, 19:49
most likely


<?php
include (someFile.txt);
?>

wherever you had your "dynamic" content

apreichner
July 8th, 2009, 00:56
most likely


<?php
include (someFile.txt);
?>

wherever you had your "dynamic" content

So what would the url to a specific page be then?

M Bacon
July 8th, 2009, 01:10
<?php
include (/home/cpanelusername/public_html/someFile.txt);
?>

WL-Michael
July 8th, 2009, 02:19
So what would the url to a specific page be then?
Yes,

Such as a header page, content section and footer. All in separate php files if you may.

apreichner
July 8th, 2009, 16:20
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.

Tree
July 8th, 2009, 22:35
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
$pages = array('page1','page2','etc');
if (in_array($_GET['page'],$pages)) {
include($_GET['page'].'.txt');
} else {
include('page1.txt');
}
?>

skolapper
September 3rd, 2009, 16:20
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