使用CURL检测坏链接引用者邻域

使用CURL检测坏链接引用者邻域

问题描述:

I'm trying to use CURL to assess the visitors on my site. I'd like to see if they are being linked from a bad neighborhood or not. Most of the time my current code works, but not always.

I'm having a bit of trouble making my CURL able to fool all servers. How do I make my CURL headers totally convincing, and remove any possible clues that I'm using 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';
}

?>

For example, a certain well known adult video site with an orange logo that looks a lot like the YouTube logo (maybe you guys know the one) responded with this:

403 Forbidden

Request forbidden by administrative rules. 
__SERVERNAME__

我正在尝试使用CURL来评估我网站上的访问者。 我想看看他们是否与坏邻居联系起来。 大部分时间我的当前代码都有效,但并非总是如此。 p>

我在使用CURL能够欺骗所有服务器时遇到了一些麻烦。 如何让我的CURL标题完全令人信服,并删除任何可能的线索,我正在使用CURL? p>

 &lt;?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 [] ='接受: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 [] ='缓存 -Control:no-cache'; 
 $ headers [] ='Content-Type:application / x-www-form-urlencoded;  charset = utf-8'; 
 $ headers [] ='主持人:www.example.com'; 
 $ headers [] ='参考者:http://www.example.com/index.php';  //你的推荐人地址
 $ headers [] ='用户代理:Mozilla / 5.0(X11; Ubuntu; Linux i686; rv:28.0)Gecko / 20100101 Firefox / 28.0'; 
 $ headers [] ='X-  MicrosoftAjax:Delta = true'; 
 
 ncurl_setopt($ ch,CURLOPT_HTTPHEADER,$ headers); 
 
 $ server_output = curl_exec($ ch); 
 
print $ server_output; 
 
 ncurl_close($ ch);  
 
 nif(strpos($ output,'sex')!== false)
 {
 echo'sex'; 
} 
 
?&gt; 
  code>  pre> \  n 
 

例如,某个知名的成人视频网站带有橙色徽标,看起来很像YouTube徽标(也许你们都知道那个)回复: p>

  403 Forbidden 
 
请求被管理规则禁止。  
__SERVERNAME __ 
  code>  pre> 
  div>

In chrome dev tools, you can obtain the full HTTP request chrome used against a URL by:

  • opening dev tools
  • goto the "network" tab
  • request the URL you want - if you are already on the target page - hit F5 or reload.
    Dev tools will then generate a list of HTTP requests (and responses) made
  • right click on the HTTP request / URL you are interested in
  • click the "save as curl" option and you will now have the full HTTP request details (for command line curl ) in your clipboard.

By using these values when sending an HTTP request your request will ostensibly appear to be made by a Chrome web browser.