使用CURL检测坏链接引用邻居


Detect bad link referrer neighborhood using CURL

我正在尝试使用CURL来评估我网站上的访问者。我想看看他们是否来自一个糟糕的社区。大多数时候,我当前的代码都能工作,但并非总是如此。

我有点麻烦,使我的CURL能够欺骗所有服务器。我如何使我的CURL标题完全令人信服,并删除任何可能的线索,我正在使用CURL?

<?php 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://www.example.com");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$vars);  //Post Fields
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = array();
$headers[] = 'X-Apple-Tz: 0';
$headers[] = 'X-Apple-Store-Front: 143444,12';
$headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
$headers[] = 'Accept-Encoding: gzip, deflate';
$headers[] = 'Accept-Language: en-US,en;q=0.5';
$headers[] = 'Cache-Control: no-cache';
$headers[] = 'Content-Type: application/x-www-form-urlencoded; charset=utf-8';
$headers[] = 'Host: www.example.com';
$headers[] = 'Referer: http://www.example.com/index.php'; //Your referrer address
$headers[] = 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) Gecko/20100101 Firefox/28.0';
$headers[] = 'X-MicrosoftAjax: Delta=true';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$server_output = curl_exec ($ch);
print $server_output;
curl_close ($ch);    
if (strpos($output,'sex') !== false) 
{
    echo 'sex';
}
?>

例如,某个知名的成人视频网站有一个橙色的标志,看起来很像YouTube标志(也许你们知道这个),回应是:

403 Forbidden
Request forbidden by administrative rules. 
__SERVERNAME__

在chrome开发工具中,您可以通过以下方式获得针对URL使用的完整HTTP请求chrome:

  • 打开开发工具
  • 转到"网络"选项卡
  • 请求你想要的URL——如果你已经在目标页面上了——点击F5或重新加载
    然后,开发工具将生成所做HTTP请求(和响应)的列表
  • 右键单击您感兴趣的HTTP请求/URL
  • 单击"另存为curl"选项,您将在剪贴板中获得完整的HTTP请求详细信息(对于命令行curl)

通过在发送HTTP请求时使用这些值,您的请求表面上看起来是由Chrome网络浏览器发出的。