Solved

server wont allow / in php includes

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

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 109

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 109

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Do you need to unset the session variable after CSRF token check passes? 2 40
Google Maps API and PHP 25 30
PHP AJAX JSON 2 61
showing loader for php/mysql/ajax live search 13 24
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

773 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