odd include() problem

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
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

odd include() problem

Post by psurrena »

I'm trying to get an include to work. The code below works fine when the URL has no mod_rewrite.

Code: Select all

<?php include (BASE_URL.'newWRT/includes/navigation/'.$menu); ?>
When the URL is rewritten I get this error:

Code: Select all

An error has occured in script 'C:\wamp\www\newWRT\includes\header.php' on line 26: 
include(http://localhost/newWRT/newWRT/includes/navigation/work-static.inc) [function.include]: failed to open stream: no suitable wrapper could be found 
Date/Time:7-16-2007 11:00:01
The path is correct but it won't load the file.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

php needs a working http url wrapper to read from http://.... urls
On your system such a wrapper is either not present or disabled.
User avatar
Gente
Forum Contributor
Posts: 252
Joined: Wed Jun 13, 2007 9:43 am
Location: Ukraine, Kharkov
Contact:

Post by Gente »

Do you really want to include your file through HTTP?
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Post by psurrena »

I don't understand what a http url wrapper is. I thought a URL was simply a URL...
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Post by psurrena »

I'm including through HTTP because I have yet to get an include to work while using mod_rewrite without it.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

fopen('local.file', 'r')
fopen('http://php.net', 'r');
fopen('ftp://xyz.com');
three different protocols, i.e. different methods of accessing the data. But yet in all three cases I can use the same function fopen or fread or include or file_get_contents or ....
The code units that make this little magic possible are called url wrappers. They are wrapped around the actual implementation for retrieving from an url (or sending to an url) to make them all more or less "appear to be the same".
psurrena wrote:I'm including through HTTP because I have yet to get an include to work while using mod_rewrite without it.
:?:
I don't understand what you're trying to achieve but it sounds like yet another good reason not to use http://... for this include.
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Post by psurrena »

I use http because when using mod_rewrite, relative includes where the file was in a subdirectory would not load since the path was relative to a "fake" URL.

So my two questions are:
1) Why is http bad?
2) What should a proper include look like? When I use

Code: Select all

<?php include ('./includes/navigation/'.$menu); ?>
it show nothing, not even an error.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Your problem is very intriguing. I use mod_rewrite all the time and I use relative includes as well, and have never had an issue with including.
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Post by psurrena »

It's intriguing to me too ;)

I think my rewrites are correct...

Code: Select all

RewriteRule ^work/location/(.*)-(.*).html$ work.php?mode=loc&name=$1&id=$2
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

If you access a file through the local filesystem relative paths are relative to the current working directory (cwd) which is not so much affected by mod_rewrite.
In case of doubt use

Code: Select all

echo '<div>cwd: ', getcwd(), "</div>\n";
to print the cwd before using include/require/file/file_get_contents

Where's work-static.inc located in the local file system? In case of doubt use

Code: Select all

echo '<div>location: ', __FILE__, "</div>\n";
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Including remote pages is quite dangerous.
Post Reply