简体   繁体   English

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

[英]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.

相关问题 如果使用cURL或Wget访问页面,则在PHP中检测 - Detect in PHP if page is accessed with cURL or Wget 我的网站是通过直接 URL 访问的,但不是通过我购买的域名访问的。 如何解决问题? - My website is accessed by direct URL but not by the domain name I bought. How to solve the issue? 检测正在访问该应用程序的 URL - Detect URL that app is being accessed from 如何保护所有点 (.) 文件以通过直接 URL 访问 - How to protect all dot (.) files to access via direct URL 如何检测php curl中的URL Not Found错误? - How can I detect URL Not Found Error in php curl? 如何在Mac Terminal上通过curl访问php URL - How to access php URL via curl on Mac Terminal 如何防止无法通过URL直接访问codeigniter中的一个特定视图? - How do i prevent one specific view in codeigniter not to be accessed directly via url? 如何重定向到带有密码的页面,但无法通过 URL 访问该页面? - How can I redirect to a page with a password, but the page cannot be accessed via URL? 如何检测是否正在访问或请求文件? - How to detect if file is being accessed or requested? 如何检测用户在iframe或直接网址中打开我的Facebook应用程序 - How do I detect either users open my Facebook app in iframe or direct url
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM