Solved

server wont allow / in php includes

Posted on 2012-04-02
5
362 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
  • 3
  • 2
5 Comments
 
LVL 108

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 108

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 34

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 34

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 108

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
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 dynamically set the form action using jQuery.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now