Click to See Complete Forum and Search --> : Some help...


Vilu Daskar
01-29-2005, 12:35 AM
I am looking for some help on expanding a PHP code that I am currently using. The script I have now, shown below, takes a txt file, and includes the header/footer beside it. So, index.php?p=main..
I am sure you have all seen this before. ;)

<?php { include("header.html"); }
if($p) {
$p = basename($p);
$p .= ".txt";
if (is_file("./$p")) {
include($p);
} else {
echo "The file you are looking for, index.php?p=$p is either not yet completed, or is missing.<br>Please keep looking back as I am constantly updating this section of the site.";
}
} else {
include("main.txt");
} { include("footer.html"); } ?>

My question is, can I get it to look through different folders for the txt files? As in, index.php?folder=test&page=main - which would turn out including /test/main.txt along with the header/footer.

I have seen this done on many different sites, but can't seem to figure it out!

Any help would be great!

~Vilu Daskar

ShrineDesigns
01-29-2005, 01:33 AM
yes i can be done, but done incorrectly could lead to security problems, for example most of those site you see doing that are made by noobs and with those script you can access almost every file on the server

try this<?php
$root = './';
// a list of valid files to include
$pages = array('home.txt', 'links.txt', 'path/to/etc.txt');

if(!isset($_GET['page']) && !array_key_exist($_GET['page'], $pages))
{
exit("access denied");
}
include($root . $pages[$_GET['page']]);
?>

Vilu Daskar
01-29-2005, 09:08 AM
So, that requires me to make a list of all the files that I want to include.
Safe for sure, but is there a more secure way - so I can just add the files to a subfolder and make it work, and add a domain halt thing, so that if it includes a reference to a different domain, the script dies?

Thanks for your help!

~Vilu Daskar

ShrineDesigns
01-29-2005, 02:49 PM
no problem