My php script used to open remote url but now it does not work.
The allow_url_fopen is now set to off on all our servers to increase
allow_url_fopen allows a programmer to open/include a remote file using a url
rather than a local file path.
You can still use this function in the form of
Many programmers include files by pointing to remote url, even if the file is on
the local system.
<?php include("http://example.com/includes/example_include.php"); ?>
With allow_url_fopen set to Off, this method will no longer work. Instead, the
file must be included with the local path by doing either one the following
1. Using relative path, such as ../includes/example_include.php
2. Using absolute path, such as /home/username/public_html/includes/exampe_include.php
3. Using PHP environment variable $_SERVER['DOCUMENT_ROOT'], which returns the
absolute path to the web root directory.
<?php include($_SERVER['DOCUMENT_ROOT']."/includes/example_include.php"); ?>
Passing Variables to an include file:
It is worth mentioning that the alternative solutions presented here will result
in a difference in the way the include() function is handled. The alternative
solutions all return the PHP code from the included page; however, the
now-unavailable remote URL method returns the result from the included page. One
result of this behavior is that you cannot pass a querystring using the
alternative solutions. You define the variables locally before performing the
<?php include("http://example.com/includes/example_include.php?var=example"); ?>
must be changed to:
$var = "example";
For maximum flexibility when using multiple includes, it's easier to create a
$doc_root = $_SERVER['DOCUMENT_ROOT'];
Note: The technique works in the same way, regardless of whether you are using
include() or require().