URL in php (include) does not work

0

I'm trying to insert a file with include , but for some reason it does not work with the full URL.

This works:

<?php include 'menu.html' ?>

But this is not the case:

<?php include 'http://domainname.com/menu.html' ?>

Any ideas?

PS: I understand the security risk of doing this.

    
asked by José Miguel Sepulveda 07.06.2017 в 15:36
source

4 answers

7

In order to remotely include files, you must set the allow_url_include, allow_url_fopen directives in on in the file php.ini .

From the security point of view, it is bad to do it, that is why it is generally disabled.

And try to include it like this:

<?php 
    include 'http://domainname.com/menu.html'; 
?>

Here you can see some reasons why it is not recommended: link

    
answered by 07.06.2017 / 15:53
source
1

It is possible to include remote files in PHP, as the documentation says:

  

If the " wrappers URL include " are enabled in PHP , It can   specify the file to be included using a URL (via HTTP or other   supported wrapper - see Supported Protocols and Wrappers for   a list of protocols) instead of a local path. If he   target server interprets the target file as PHP code, the   variables can be passed to the included file using a string of   request as used with HTTP GET. This is not, strictly speaking, what   same as having included the file and having inherited the scope of   variables of the parent file; the script is really being executed   on the remote server and the result is then included within the   local script.

For more specific details on the inclusion of HTML files you can see the PHP Manual information about it .

Anyway:

A.

If your file is on the same server, the way to include it is by referring to the path in which the file is located, as the Manual says:

  

The files are included based on the given path or, if   none is given, the include_path specified. If the file is not   found in the include_path , include will finally verify in the   own directory of the script that makes the call and in the directory of   current work, before failing. The include constructor will emit a   warning if you can not find a file, this is a   behavior different from that of require, which will emit an error   fatal ..

The path in this case refers to the path on the server, not to a URL path.

B.

If your file is on another server, I would not recommend never to include files from another server, you would have to modify the php.ini setting allowing a dangerous access , which would be more expensive and insecure than copying said file on the server itself and include it by the normal way indicated in A .

    
answered by 07.06.2017 в 16:18
0

The include does not work for remote files. It only includes the same file system.

    
answered by 07.06.2017 в 15:56
0

this should work

$handler = curl_init("http://domainname.com/menu.html");  
$response = curl_exec ($handler);  
curl_close($handler);  
echo $response

put it where the menu goes

greetings

note: research more about curl for more options

    
answered by 07.06.2017 в 17:17