Solved

server wont allow / in php includes

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

733 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