0

Possible Duplicate:
how to prevent PHP's file_get_contents( )

I want to prevent file_get_contents from other sites to protect my contents not be stolen from other sites. I found a topic like this but It seems not very clear to me. how to prevent PHP's file_get_contents( )

Any helps? Example http://ddth.com. You couldn't file_get_contents("http://ddth.com");

4

1 回答 1

1

您可以使用 HTTP 身份验证来保护

$login = 'root';
$pass = '12345';

if(($_SERVER['PHP_AUTH_PW']!= $pass || $_SERVER['PHP_AUTH_USER'] != $login)|| !$_SERVER['PHP_AUTH_USER'])
{
 header('WWW-Authenticate: Basic realm="Test auth"');
 header('HTTP/1.0 401 Unauthorized');
 echo 'Auth failed';
 exit;
}

else
{
 echo "ok";
 }

并且可以使用 curl 阅读

    $username = 'user';
    $password = 'password';
    $ip = $_SERVER["SERVER_ADDR"];      
    $browser_id = "Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3";
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url); 
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
    curl_setopt($curl, CURLOPT_USERAGENT, $browser_id);
    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($curl, CURLOPT_TIMEOUT, 15);
    curl_setopt($curl, CURLOPT_REFERER, $ip);       
    $retValue = curl_exec($curl);
    $err = curl_error($curl);
    curl_close($curl);

要提取信息,请在此处输入代码

于 2012-10-05T15:29:42.993 回答