agh! include program!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Patriot
Forum Commoner
Posts: 34
Joined: Tue Jun 18, 2002 1:36 pm

agh! include program!

Post by Patriot »

<?
$ext = ".php";
$id = "".$id."".$ext."";

if (file_exists($id))
{
include($id);

} else {
include ("404.php");

}
?>

if i have this ^ to get rid of having to type
mysite.com/root.php?id=main.php
it messes my website up.
like when i try to do this:
http://mysite.com/root.php?id=download/ ... file=1.zip

it always shows 404.php
Shadough
Forum Newbie
Posts: 20
Joined: Tue Jun 04, 2002 9:11 pm

Post by Shadough »

Try

Code: Select all

$ext = '.php';
$id = $_GET&#1111;'id'] . $ext;

if (@file_exists($id)) &#123;
 @include_once($id);
&#125; else &#123;
 @include_once('404.php');
&#125;
?>
THe "@" will prevent PHP from error reporting.

$id = "".$id ....

that dot i think messed it up.
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

If this is the URL you are using to determine whether the file exists

Code: Select all

http://mysite.com/root.php?id=download/download.php?category=Windows&subc=Archive&file=1.zip
then id will = download/download.php?category=Windows&subc=Archive

when the system looks for this file it obviously does not exist.

try :

Code: Select all

$fileExists = substr($id, 0, strpos($id,"?") - 1);
if (file_exists($fileExists)) &#123;
    header("Location: $id");
&#125;  else  &#123;
    header("Location: 404.php");
&#125;
Post Reply