[英]How to detect, a URL accessed direct or via 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);
?>
You can't. 你不能 An HTTP request is an HTTP request, and you've ruled out the obvious distinguishing characteristic of a request made by a browser (the contents of the user-agent header). HTTP请求是HTTP请求,您已经排除了浏览器发出的明显区别特征(用户代理标头的内容)。
Since curl work as like any browser, so it is difficult to detect that is man or machine. 由于curl可以像任何浏览器一样工作,因此很难检测到是人还是机器。 For that first of all, you can 首先,您可以
1.print $_SERVER php variable
2.json_encode this variable
3.put in a database field named server information
4.then browse this site one time
5.and curl execute for this same URL
6.then print both information
Here you can see some different issue. 在这里您可以看到一些不同的问题。 I have found different terms HTTP_COOKIE which not exist in curl request information. 我找到了卷曲请求信息中不存在的不同术语HTTP_COOKIE。
So you can detect 这样你就可以发现
if (!isset($_SERVER['HTTP_COOKIE'])) {
die('Opps! I think, your request is not proper way. Please contact');
}
I think that will be very helpful who want to protect data scrapt from his/her website. 我想这对想要保护从他/她的网站上抓取的数据的人非常有用。
see details http://saidul.songzog.com/my-blog/details/869/how-can-detect-how-to-detect-a-url-accessed-direct-or-via-curl.html 查看详细信息http://saidul.songzog.com/my-blog/details/869/how-can-detect-how-to-detect-a-url-accessed-direct-or-via-curl.html
You can check the visitor's user agent by 您可以通过以下方式查看访问者的用户代理
_SERVER['HTTP_USER_AGENT']
note that it can be modified when using curl with the -A flag. 请注意,在将curl与-A标志一起使用时,可以对其进行修改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.