Solved

server wont allow / in php includes

Posted on 2012-04-02
5
376 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

 Database Backup and Recovery Best Practices

Join Percona’s, Architect, Manjot Singh as he presents Database Backup and Recovery Best Practices (with a Focus on MySQL) on Thursday, July 27, 2017 at 11:00 am PDT / 2:00 pm EDT (UTC-7). In the case of a failure, do you know how long it will take to restore your database?

Question has a verified solution.

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

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

630 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