...

View Full Version : error include url



eric float
07-22-2008, 06:03 AM
i have two problem with url in my code . Example :
<?PHP if (empty($_GET[page])) $_GET[page] = home; include "$svr_rootself/$_GET[page].php"; ?>
with this method my url is www.mysite.com/?page=example&ex=2&exe=3 . ( example=example.php in server root and worked 100&#37; ) now when change manually url to ?page=example.php i have two error .

Warning: include(htdocs/site/example.php.php) [function.include]: failed to open stream: No such file or directory in htdocs\site\index.php on line 49

Warning: include() [function.include]: Failed opening 'htdocs/site/detail.php.php' for inclusion (include_path='.;\php\pear\') in site\index.php on line 49
how to fix this error ? regards

abduraooft
07-22-2008, 08:13 AM
include "$svr_rootself/$_GET[page].php"; The above code assumes $_GET[page] contains the name of the file and no extension.
So
www.mysite.com/?page=example would include

include "$svr_rootself/example.php"; and
?page=example.php would try to include example.php.php, which may not be available. However ?page=example this should work.

PS: $_GET['page'] is the proper way to access global array variables.
You need to add a code to check whether the file is actually present in that directory (file_exists() (http://www.php.net/file_exists)). Otherwise a request like ?page=blah will always give an error

eric float
07-23-2008, 09:25 AM
any idea for fix this error ??

mic2100
07-23-2008, 09:52 AM
try this and show me ur results



<?PHP if (empty($_GET[page])) $_GET[page] = home; include $svr_rootself."/".$_GET[page]; ?>

eric float
07-23-2008, 10:27 AM
no ! not worked this code .

Fou-Lu
07-23-2008, 10:49 AM
The error indicates that you cannot find the file, or that the file cannot be read. Make sure that the file exists in the location its seeking, and that you're server has read access to the file. Abdura already mentioned about the ?page=example.php, which is also what you're error shows: Failed opening 'htdocs/site/detail.php.php'. Don't worry about the two errors, they both equate to one problem. The set to $_GET[page] = home; should also be $_GET['page'] = 'home';, since home refers to a constant while 'home' refers to a string. I would debug like so:


<?php

if (!isset($_GET['page']) || empty($_GET['page']))
{
$_GET['page'] = 'home';
}

$fileSeek = $svr_rootself . '/' . $_GET['page'] . '.php';
printf("File '&#37;s' exists? %s\n", $fileSeek, (file_exists($fileSeek)) ? 'yes' : 'no');
printf("File '%s' is readable? %s\n", $fileSeek, (is_readable($fileSeek)) ? 'yes' : 'no');
include $fileSeek;

If either of those say 'no', you've got a problem with either no file, or being unable to read the file. If the file is there, chmod or chown the file if you're on linux, manually assign on windows.

eric float
07-23-2008, 11:04 AM
my idea is : when page=example to page=example.php direct page to any page for error ! so example : mysite.com/index.php?page=example.php direct to mysite.com/anypage.php ( YOUR PAGE NOT Exit ) or any text error .


The error indicates that you cannot find the file, or that the file cannot be read. Make sure that the file exists in the location its seeking, and that you're server has read access to the file. Abdura already mentioned about the ?page=example.php, which is also what you're error shows: Failed opening 'htdocs/site/detail.php.php'. Don't worry about the two errors, they both equate to one problem. The set to $_GET[page] = home; should also be $_GET['page'] = 'home';, since home refers to a constant while 'home' refers to a string. I would debug like so:


<?php

if (!isset($_GET['page']) || empty($_GET['page']))
{
$_GET['page'] = 'home';
}

$fileSeek = $svr_rootself . '/' . $_GET['page'] . '.php';
printf("File '&#37;s' exists? %s\n", $fileSeek, (file_exists($fileSeek)) ? 'yes' : 'no');
printf("File '%s' is readable? %s\n", $fileSeek, (is_readable($fileSeek)) ? 'yes' : 'no');
include $fileSeek;

If either of those say 'no', you've got a problem with either no file, or being unable to read the file. If the file is there, chmod or chown the file if you're on linux, manually assign on windows.
Fou-Lu Your code not worked . thanks

Fou-Lu
07-23-2008, 11:05 AM
I understand what you are trying to do. What does the output for the above debugging produce, is it yes or no?


I didn't say my code would work. I said thats how I would debug it. Remember, we're here to help you, not fix you're code for you.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum