帝国CMS技术互助群:540946827 一帮大神带你装逼带你飞!还有漂亮的妹纸陪你玩哦!
使用的file_get_contents获取页面内容后,我们可以使用$ http_response_header获取响应头信息,响应头信息里面一般包括饼干变量的值,具体实现代码如下:
file_get_contents('http://example.org');
$cookies = array();
foreach ($http_response_header as $hdr) {
if (preg_match('/^Set-Cookie:\s*([^;]+)/', $hdr, $matches)) {
parse_str($matches[1], $tmp);
$cookies += $tmp;
}
}
/* http://www.pouyao.com/article/1429.html */
print_r($cookies);
例外一种方法可以使用stream_get_meta_data()得到实现:
if (false !== ($f = fopen('http://www.example.org', 'r'))) {
$meta = stream_get_meta_data($f);
$headers = $meta['wrapper_data'];
$contents = stream_get_contents($f);
fclose($f);
}
// $headers now contains the same array as $http_response_header
具体代码如下:
$opts = array('http' => array('header'=> 'Cookie: ' . $_SERVER['HTTP_COOKIE']."\r\n"));
$context = stream_context_create($opts);
/* http://www.manongjc.com/article/1430.html */
$contents = file_get_contents('http://example.com/test1.txt', false, $context);
echo $contents;
?>
如对本文有疑问,请提交到交流社区,广大热心网友会为你解答!! 点击进入社区
打赏一下,我们会为大家提供更多优质资源!
您的打赏将全部用来搜集更多优质资源!
扫码打赏,你说多少就多少
打开微信扫一扫,即可进行扫码打赏哦