How do I CURL www.google.com - it keeps redirecting me to .co.uk

前端 未结 7 2522
南笙
南笙 2021-02-19 16:06

I am using CURL to check for the existence of a URL (HEAD request) but when I test it with www.google.com, it redirects me to www.google.co.uk - probab

7条回答
  •  被撕碎了的回忆
    2021-02-19 17:10

    One way to avoid Google from deciding what country you are in, is by setting a different IP address. Just get one of the many US proxy servers from the Web and do something like this:

    $ch=curl_init();
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_FOLLOWLOCTION,1); 
    curl_setopt($ch,CURLOPT_PROXY,"8.12.33.159");
    curl_setopt($ch,CURLOPT_PROXYPORT,"80");
    curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3");
    curl_setopt($ch,CURLOPT_URL,$URI);
    $results=curl_exec($ch);
    curl_close($ch);
    

    This way, Google will think you come form a US IP address and not redirect to a local Google.

提交回复
热议问题