Solved

server wont allow / in php includes

Posted on 2012-04-02
5
371 Views
Last Modified: 2012-04-02
hello, A very weird problem...

I made an include file which has just html in it.

i use this to include it, and I can go to the address and view the view
<?php include("/new_site/main_includes/news-tips-menu.php"); ?>

but my php code gives me these weird errors and wont include the file
(I changed allow_url_include=1 all that did was made 1 warning go away)

Warning: include() [
function.include
]: http:// wrapper is disabled in the server configuration by allow_url_include=0 in /home/thinkins/public_html/new_site/include_main_nav.php on line 6

Warning: include(http://www.website.ca/new_site/main_includes/news-tips-menu.php) [
function.include
]: failed to open stream: no suitable wrapper could be found in /home/thinkins/public_html/new_site/include_main_nav.php on line 6

Warning: include() [
function.include
]: Failed opening 'http://www.website.ca/new_site/main_includes/news-tips-menu.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/thinkins/public_html/new_site/include_main_nav.php on line 6



these fail

include('http://www.website.ca/new_site/main_includes/news-tips-menu.php');
include("/new_site/main_includes/news-tips-menu.php");

these works

include('../main_includes/news-tips-menu.php');
include('main_includes/news-tips-menu.php');
0
Comment
Question by:jblayney
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 37797762
It looks like the script calling the include() function is located in the /new_site/ directory.  So I would just use the last example.  Assuming you have current software, you should be able to get allow_url_fopen and allow_url_include to work.  You have to set both of them to "on" and you may have to restart PHP.
http://hp.net/manual/en/filesystem.configuration.php

HTH, ~Ray
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 37797769
PS: Going forward you might want to have a test bed that you can wipe out and recreate at any time.  Then you will not have to worry about posting a client URL - you can just post the URL of the test bed.

All the best, ~Ray
0
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 37797785
That is probably because when the slash is the very first character, the path starts at the root of the filesystem (assuming there's been no custom chroot / jail), so "new_site" probably isn't a folder that far down.

In other words, your FULL path is:

/home/thinkins/public_html/new_site/main_includes/news-tips-menu.php

So when you try to include /new_site/main...etc..., it can't find it. If you have the slash at the beginning it would look like:

include("/home/thinkins/public_html/new_site/main_includes/news-tips-menu.php");

When you use ".." or if you don't include the slash at the beginning, then it is looking for that path relative to your current directory.

If your server configuration disallows allow_url_include, then there's probably not much you can do about it, but there's really no reason you should ever do this:

include("http://any url at all here")

That is a TERRIBLE idea. You're basically running PHP code that is coming in from the network, and to be honest, you cannot be certain that nobody has tampered with that data when it was outside of your server. So you could be inviting hacking attempts by doing that.

If you ever use include(), then always include with a local path on the filesystem.
0
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 37797792
You may be wanting to include the final RESULT of your news-tips-menu.php, in which case you could do something like this:

echo file_get_contents("http://......etc...../news-tip-menu.php");

See if that does what you want it to do. If so, then try it out for a bit. You can probably incorporate caching into your project to make this process go faster (so your PHP script isn't going and downloading that file every time), but first see if that's what you want.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 37797806
Uhh, check that first link.  It should be http://php.net/manual/en/filesystem.configuration.php
0

Featured Post

Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question