如何检测,直接访问或通过CURL访问的URL

-1 php curl

// remote.php on http://www.example.com/
<?php
function curl_access()
{ /*
  some codes here to detect
  this script accessed via
  curl or direct and returns $r.
  (without checking referrer or user agent)
  */
  return $r;
}
$curl_access = curl_access();
if ($curl_access)
{ echo 'Accessed via CURL';
} else
{ echo 'Direct access';
}
?>

// some file on a server
<?php
$h = curl_init();
curl_setopt($c, CURLOPT_URL, "http://www.example.com/remote.php");
curl_exec($c); // returns 'Accessed via CURL'
curl_close($c);
?>
Run Code Online (Sandbox Code Playgroud)

Que*_*tin 7

你不能.HTTP请求是一个HTTP请求,您已经排除了浏览器发出的请求(用户代理标头的内容)的明显区别特征.