Bypass error allow_url_include = 0

I am trying to include a file from a URL, however I am getting the following error:

Warning: include(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in /Applications/MAMP/htdocs/diningtime/testsite/salims/index1.php on line 58 Warning: include(http://localhost/diningtime/templates/100/index.php): failed to open stream: no suitable wrapper could be found in /Applications/MAMP/htdocs/diningtime/testsite/salims/index1.php on line 58 Warning: include(): Failed opening 'http://localhost/diningtime/templates/100/index.php' for inclusion (include_path='.:/Applications/MAMP/bin/php/php5.4.4/lib/php') in /Applications/MAMP/htdocs/diningtime/testsite/salims/index1.php on line 58 Test 

Just wondering if there is any in this case?

My PHP enable code

 <?php include "$location/index.php"; ?> 

I appreciate your help with this.

+4
source share
2 answers

You use the full URL as you add the path that PHP tells you to try to execute an HTTP request to retrieve this file. This is NOT how you do it. If this ...100/index.php does not output PHP code, you will get some kind of HTML or something as the result of the include, not the php code in the file. Remember - you are retrieving the URL, which means it is an HTTP request, which means that the web server will EXECUTE this script and deliver its output, and not just execute its source code.

The web server cannot say that the HTTP request for this script is an include call from another PHP script on the same server. It would also be easy to request this script from some hacker hiding in Russia who wants to steal your source code. Do you want your source code to be visible to the whole world?

For local files, you should never use a full-blown URL. it is terribly inefficient and will not do what you want. why not just

 include('/path/to/templates/100/index.php'); 

instead, which would be a local file-only request, without including an HTTP step?

+20
source

I had a similar problem.

Given Marc B's post, it’s clear that using absolute URLs is not a great idea, even if possible by editing php.ini as “ficuscr”. I'm not sure if this workaround will work for your specific situation, as it still requires adjusting each page depending on where it is located in your folder structure, but it makes things easier if, like me, you have a lot of site.

 <?php $root="../";?> <?php include($root . 'folder-A/file_to_be_included_1.php');?> <?php include($root . 'folder-A/file_to_be_included_2.php');?> <?php include($root . 'folder-B/file_to_be_included_3.php');?> <?php include($root . 'folder-B/file_to_be_included_4.php');?> <?php include($root . 'folder-B/sub-folder/file_to_be_included_5.php');?> 

For me, this means that if I moved the page to another place in the folder structure, for example, to a subfolder of my current location, all I need to do is change <?php $root="../";?> So that become <?php $root="../../";?> , for example

+1
source

Source: https://habr.com/ru/post/1444657/


All Articles