PDA

View Full Version : Include not working?


Nightfire
10-23-2002, 03:14 PM
I'm trying to add include by an if statement.


if(file_exists(''.$url.'/includes/'.$action.'.php')){
include(''.$url.'/includes/'.$action.'.php');
}else{
include(''.$url.'/includes/filenotfound.php');
}


This doesn't seem to work, I get an error saying that it failed to open the included file, but prints out the full url to the file.

Warning: Failed opening 'http://localhost/chatterspics2/includes/filenotfound.php' for inclusion (include_path='') in c:\php\www\chatterspics2\index.php on line 10

If I follow that url shown in the error, the file is shown. So can I do this in an if statement? I've got files included elsewhere in the page for the header for example

include(''.$url.'/includes/header.php')

and that works fine.

Ökii
10-25-2002, 12:02 PM
Is includes/filenotfound.php actually there? case-sensitive?

Other than that, try relative linking the files.

Nightfire
10-25-2002, 12:07 PM
Yeah it's there. That's what I don't understand coz if I include it that way outside the if statement, it works :confused:

I wanted to try not to use relative links as it's going to be used on many sites (for a program I'm making). Be a bit awquard if they're having to edit pages just to get it to work :(

Thanks for your help anyway :)

firepages
10-25-2002, 12:53 PM
does...

<?
if(is_file($url.'/includes/'.$action.'.php')){
include($url.'/includes/'.$action.'.php');
}else{
include($url.'/includes/filenotfound.php');
}
?>

work ? - cos I don't understand the space before the $url ??

Nightfire
10-25-2002, 01:02 PM
Nah, doesn't work either. Same error about the files not being found.

this is my whole page:

<?
include($url.'/includes/header.php');
if(!session_is_registered("username")){
if(!$action){
include($url.'/includes/home.php');
}else{

if(is_file($url.'/includes/'.$action.'.php')){
include($url.'/includes/'.$action.'.php');
}else{
include($url.'/includes/filenotfound.php');
}


}
}else{
if(!$action){
include("includes/homefm.php");
}else{
if(file_exists('includes/'.$action.'fm.php')){
include('includes/'.$action.'fm.php');
}else{
include('includes/filenotfound.php');
}
}
}
?>


The first include works, for the header. The rest don't seem to be working :confused:

firepages
10-25-2002, 01:31 PM
it has to work !! :)

(not saying it is it oughta ...)
try,


<?
include($url.'/includes/header.php');
if(!isset($_SESSION['username']))
{
if(!$action)
{
include($url.'/includes/home.php');
}else{
if(is_file($url.'/includes/'.$action.'.php'))
{
include($url.'/includes/'.$action.'.php');
}else{
include($url.'/includes/filenotfound.php');
}
}
}else{
if(!$action)
{
include($url.'/includes/homefm.php');
}else{
if(is_file($url.'/includes/'.$action.'fm.php'))
{
include($url.'/includes/'.$action.'fm.php');
}else{
include($url.'/includes/filenotfound.php');
}
}
}
?>

Nightfire
10-25-2002, 02:02 PM
Same thing again *cries*

Warning: Failed opening 'http://localhost/chatterspics2/includes/filenotfound.php' for inclusion (include_path='') in c:\php\www\chatterspics2\index.php on line 14

The page is there, all I have to do is c&p that url into me address bar and the page shows.

I think I'm gonna leave it and find another way to do it.

bcarl314
10-25-2002, 02:30 PM
Ohh, ohh I think I know the problem!

PHP cannot inculde files via http: on a windows platform. I've had this problem before. Try uploading to a *nix box and see if it works! (Remember to change your "\" to "/"!

Nightfire
10-25-2002, 02:53 PM
:( I'll find another way to do it. It's still doing the same thing on a linux server. Thanks for your help :)

Bawy
10-25-2002, 06:40 PM
Windows works fine for includes from anywhere as long as your firewall doesn't stop it. Try using a relative URL instead of absolute:

Instead of this as URL:
http://localhost/chatterspics2/

try this (assuming that is your web root, I can't see your directory structure)

/chatterspics2/

Nightfire
10-25-2002, 06:44 PM
It works that way, it also works using the way I have above as I use it for the header. It just doesn't work in the if statement.

Bawy
10-25-2002, 06:45 PM
Try executing this to help you find the root of the problem:

if(file_exists($url.'/includes/filenotfound.php')) echo 'file exists<br>';
if(is_file($url.'/includes/filenotfound.php')) echo 'is file';


Maybe dump the parenthesis???
if(...) {
include $url.'/includes/filenotfound.php';
}

Also, here is a workaround:

if(file_exists($url.'/includes/'.$action.'.php')){
$theinclude=$url.'/includes/'.$action.'.php';
}else{
$theinclude=$url.'/includes/filenotfound.php';
}
include $theinclude;

mordred
10-25-2002, 09:48 PM
This is a very interesting issue. Though I have no idea what's going on in your code on your local server, I've got some questions:

1. Which PHP version do you run on which OS?
I can only second what bcarl said previously, that http:// url wrappers for include are not active in PHP < version 4.3. Thus, I am able to reproduce your error, including a remote file is not possible on windows (I have PHP 4.2.3 installed), but I'm really astonished that you said that including works for you with URLs just no for that particular file.

2. What's actually in $url and how do you get this value?

Nightfire
10-25-2002, 09:58 PM
I'm using win98se - php 4.2.3 , my host is using linux redhat - php 4.0.6

forgot to add $url on here. It goes above the first include as

$url = "http://localhost/chatterspics2";

Nightfire
10-25-2002, 10:06 PM
I just got it fixed :) My uncle sent me his php.ini file and it's working fine. I guess there's something I missed out?

Thanks for your help :)

Bawy
10-26-2002, 05:31 PM
If php.ini fixed it, perhaps had something to do with the include_path or you were in safe mode with some restrisction on includes