在使用file_get_contents函数请求页面时,我们可以配置php.ini文件来发送user agent信息,那如何设置HTTP头信息呢?具体实现请看下面源码:

<?php
// Create a stream
$opts = array(
  \'http\'=>array(
    \'method\'=>\"GET\",
    \'header\'=>\"Accept-language: en\\r\\n\" .
              \"Cookie: foo=bar\\r\\n\"
  )
);

$context = stream_context_create($opts);
/*  http://www.manongjc.com/article/1425.html */
// Open the file using the HTTP headers set above
$file = file_get_contents(\'http://www.example.com/\', false, $context);
?>
收藏 打印