Page 1 of 1

agh! include program!

Posted: Tue Jun 25, 2002 8:51 pm
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

Posted: Tue Jun 25, 2002 11:25 pm
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.

Posted: Wed Jun 26, 2002 3:30 am
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;