简体   繁体   English

PHP发送的HTTP标头

[英]HTTP headers sent by PHP

I am using CURL and file_get_contents to find out the basic difference between a server request for a page and a browser request (organic). 我正在使用CURL和file_get_contents来找出服务器对页面的请求和浏览器请求(有机)之间的基本区别。

I am requesting for a PHPINFO page both ways and found that it is giving different output in different cases. 我同时请求PHPINFO页面,发现在不同情况下它提供不同的输出。

For example, when I am using a browser the PHPINFO shows this: _SERVER["HTTP_CACHE_CONTROL"] no-cache This info is missing when I am requesting the same page through PHP. 例如,当我使用浏览器时,PHPINFO显示以下内容:_SERVER [“ HTTP_CACHE_CONTROL”] no-cache当我通过PHP请求同一页面时,此信息丢失。

My CURL: 我的CURL:

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://www.example.com/phpinfo.php");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0");
    curl_setopt($ch, CURLOPT_INTERFACE, $testIP);
    $output = curl_exec($ch);
    curl_close($ch);

My file_get_contents: 我的file_get_contents:

$opts = array(
'socket' => array('bindto' => 'xxx.xx.xx.xx:0'),
'method'  => 'GET',
'user_agent '  => "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0", // this doesn't work
'header' => array('Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*\/*;q=0.8')
);

My goal: To make a PHP request look identical to a browser request. 我的目标:使PHP请求看起来与浏览器请求相同。

one of possible ways for server to detect you are a php code not a browser is check your cookie. 服务器检测到您的PHP代码而不是浏览器的一种可能方法是检查cookie。 with php curl request to the server once and inject the cookie you get to your next request. 用php curl请求到服务器一次,然后将cookie注入到下一个请求中。 check here : http://docstore.mik.ua/orelly/webprog/pcook/ch11_04.htm one other way that server can understand you are a robot(php code) is check referer http header. 检查这里: http : //docstore.mik.ua/orelly/webprog/pcook/ch11_04.htm服务器可以理解您是机器人的另一种方式(PHP代码)是检查引荐来源HTTP标头。 you can learn more here : http://en.wikipedia.org/wiki/HTTP_referer 您可以在此处了解更多信息: http : //en.wikipedia.org/wiki/HTTP_referer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM