Page 1 of 1
odd include() problem
Posted: Mon Jul 16, 2007 10:05 am
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.
Posted: Mon Jul 16, 2007 10:09 am
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.
Posted: Mon Jul 16, 2007 10:09 am
by Gente
Do you really want to include your file through HTTP?
Posted: Mon Jul 16, 2007 10:11 am
by psurrena
I don't understand what a http url wrapper is. I thought a URL was simply a URL...
Posted: Mon Jul 16, 2007 10:12 am
by psurrena
I'm including through HTTP because I have yet to get an include to work while using mod_rewrite without it.
Posted: Mon Jul 16, 2007 10:22 am
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.
Posted: Mon Jul 16, 2007 10:29 am
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.
Posted: Mon Jul 16, 2007 1:21 pm
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.
Posted: Mon Jul 16, 2007 1:40 pm
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
Posted: Mon Jul 16, 2007 2:03 pm
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";
Posted: Mon Jul 16, 2007 10:46 pm
by feyd
Including remote pages is quite dangerous.