Include Files

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
aliciadg
Forum Newbie
Posts: 16
Joined: Tue Jul 14, 2009 3:39 pm

Include Files

Post by aliciadg »

I am moving to a new server and I'm having issues with some include files. The files reside in my root web in a folder called includes (they are header and footer files). The files have the extension .inc. After to moving to the new server these work fine for locally stored files but when I call these include files from another server I get the following error:

Warning: include(http://freemanweb11.freeman.tulane.edu/ ... header.inc) [function.include]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in C:\web\webdocs\wp-content\themes\freeman\header.php on line 39

Warning: include() [function.include]: Failed opening 'http://freemanweb11.freeman.tulane.edu/ ... header.inc' for inclusion (include_path='.;C:\php5\pear') in C:\web\webdocs\wp-content\themes\freeman\header.php on line 39

In php.ini both allow_url_fopen and allow_url_includes are set to "on". The is the same set up as on the old server where everything works fine. Oddly enough if I name the include files with an extension of .php they work fine. Can anyone point me in the right direction? My brain is wracked! Thanks in advance for any assistance.
Alicia

ETA: Another oddity, the error references c:\php5\pear. This folder does not exist when I check the phpinfo the configuration file loaded for all servers is what I expect it to be. When I installed php I installed in a folder on the root of c called "php" there is no php5 folder. I can't determine where this is coming from.
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Re: Include Files

Post by Skara »

aliciadg wrote:...but when I call these include files from another server I get the following error:

Warning: include(http://freemanweb11.freeman.tulane.edu/ ... header.inc) [function.include]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in C:\web\webdocs\wp-content\themes\freeman\header.php on line 39

Warning: include() [function.include]: Failed opening 'http://freemanweb11.freeman.tulane.edu/ ... header.inc' for inclusion (include_path='.;C:\php5\pear') in C:\web\webdocs\wp-content\themes\freeman\header.php on line 39
...Maybe this is too obvious, but have you tried loading http://freemanweb11.freeman.tulane.edu/ ... header.inc in a web browser? If you can't get it there, you won't get it through include() either.
aliciadg
Forum Newbie
Posts: 16
Joined: Tue Jul 14, 2009 3:39 pm

Re: Include Files

Post by aliciadg »

...Maybe this is too obvious, but have you tried loading http://freemanweb11.freeman.tulane.edu/ ... header.inc in a web browser? If you can't get it there, you won't get it through include() either.
Yes, I tried this and I get a 404. However in this same folder I have been able to access .html and .php files. It's almost as if I need to tell something somewhere how to respond to a .inc or a .include file type....
ETA: I have double checked permissions on this folder as well.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Include Files

Post by requinix »

Don't try to access your own files (on the same server or another) over HTTP like that. It's silly. It means more bandwidth, more costs, slower loading time...

If you like those includes and want to use them then copy the files over to your server and include them from there.
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Re: Include Files

Post by Skara »

@aliciadg: including a url is the equivalent of loading it in a browser and grabbing the contents.
@tasairis: Correct. :) There's always a possibility there's a good reason to include from another server, though.
aliciadg
Forum Newbie
Posts: 16
Joined: Tue Jul 14, 2009 3:39 pm

Re: Include Files

Post by aliciadg »

tasairis wrote:Don't try to access your own files (on the same server or another) over HTTP like that. It's silly. It means more bandwidth, more costs, slower loading time...

If you like those includes and want to use them then copy the files over to your server and include them from there.
It's not really all that silly in my current environment, and is necessary in order for my users to properly maintain the site. I am dealing with over 25 users and over 50,000 files on 4 servers. Please address my issue of the include files if you have any helpful info.
aliciadg
Forum Newbie
Posts: 16
Joined: Tue Jul 14, 2009 3:39 pm

Re: Include Files

Post by aliciadg »

Skara wrote:@aliciadg: including a url is the equivalent of loading it in a browser and grabbing the contents.
@tasairis: Correct. :) There's always a possibility there's a good reason to include from another server, though.
Understood, does anyone have any input on why this might be happening?
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Re: Include Files

Post by Skara »

As I've stated before, the reason lies not in your code but in this server not being online:
http://freemanweb11.freeman.tulane.edu/
aliciadg
Forum Newbie
Posts: 16
Joined: Tue Jul 14, 2009 3:39 pm

Re: Include Files

Post by aliciadg »

It is online, it is not visible to those outside of the domain, but the server and the other server calling the include files are both online inside the same domain. My apologies for not being clear on that. As I stated before in my original post if I change the file extension from .inc to .php and I call the .php file as the include file it works.
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Re: Include Files

Post by Skara »

It is online, it is not visible to those outside of the domain
AH, sorry.. ^^;
if I change the file extension from .inc to .php and I call the .php file as the include file it works
... ^ do that. :D Or change it to .inc.php if you like. Is .inc configured in your webserver(s) to parse as a php file?
aliciadg
Forum Newbie
Posts: 16
Joined: Tue Jul 14, 2009 3:39 pm

Re: Include Files

Post by aliciadg »

Okay, so I added it to the configuration and now it's working. It is so odd, though, the .inc files were being called by files stored locally and they were working, this was only an issue when using the full url path from another server to call the .inc files....

Bahhhh! Anyway, thanks for talking me through this, it's very helpful sometimes to just discuss it! I was literally losing my mind!
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Re: Include Files

Post by Skara »

That is weird it would only break then. Anyway, glad you got it working.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Include Files

Post by JAB Creations »

A suggestion...since it's best to run a copy of a site locally (or over a network server if you're at work in example)I highly recommend having a path(ing) system. That way you can ensure your work will work with minimal effort...if you change something you would only have to point in one place or another.

Code: Select all

<?php
     if ($_SERVER['HTTP_HOST'] == "www.mydomain.com") {$truedbuser = "mycom";}
else if ($_SERVER['HTTP_HOST'] == "www.mydomain.net") {$truedbuser = "mynet";}
else if ($_SERVER['HTTP_HOST'] == "localhost") {$truedbuser = "jab";}
?>
...I do the same thing with my site's XHTML base element...

Code: Select all

<?php
echo '<base href="'.$cms->base1.$cms->base2.'" />' . "\n";
?>
...and in the $cms class I do pretty much the same thing as in my first chunk of code above to determine where everything should be located.

I also recommend looking at WHAT the current path is set versus where it's trying to include...

dir_1/dir_2/dir_3/dir_a/dir_b/
dir_1/dir_2/dir_3/dir_c/dir_d/

...find the difference and work from that. :)
Post Reply