Array
(
[0] => HTTP/1.1 200 OK
[1] => Date: Mon, 24 Dec 2012 16:15:18 GMT
[2] => Server: BWS/1.0
[3] => Content-Length: 9888
[4] => Content-Type: text/html;charset=gbk
[5] => Cache-Control: private
[6] => Expires: Mon, 24 Dec 2012 16:15:18 GMT
[7] => Set-Cookie: BAIDUID=9AFFEA9B11EC8D358FC1A13A8DCC83F9:FG=1; expires=Mon, 24-Dec-42 16:15:18 GMT; path=/; domain=.baidu.com
[8] => P3P: CP=" OTI DSP COR IVA OUR IND COM "
[9] => Connection: Close
)
用get_headers,如何取到网页头Cookie值。
解决方案 »
- JpGraph中柱状图的问题
- 数据库链接出错,问题?请教高手!
- 唠叨帮忙看看这个代码在PHP5上怎么提示错误 在PHP4上运行正常
- 大家使用smarty的时候都是采用的分界符是什么啊?我用默认的大括号,可是如果模板页面中有style标签时就会出错了
- http://baidu.com/index.php php php php php php
- 请问如何让一个程序到一个时间就自动运行
- 偶的CMS系统,现丑哦:)望大家狠狠地批
- odbc_fetch_into的问题啊!
- 关于PHP的调试?我的分没有多少,只给得起50分了?
- 新手学习PHP
- win8 R2下面 file_get_contents 失效
- 这条代码如何修改为用户名密码连接某个数据库表
$array = array('Set-Cookie: BAIDUID=9AFFEA9B11EC8D358FC1A13A8DCC83F9:FG=1; expires=Mon, 24-Dec-42 16:15:18 GMT; path=/; domain=.baidu.com');
foreach ($array as $value) {
if (stripos($value, 'Set-Cookie') !== false)
echo $value;
}
<?php
$header = get_headers('http://www.baidu.com/', true);
$c = $header['Set-Cookie'];
// 响应头里可以包含多个 Set-Cookie,所以统一为数组处理
if( ! is_array($c) ) $c = array($c);
foreach($c as $i){
$s = explode('=', substr($i, 0, strpos($i, ';')), 2);
$cookie[$s[0]] = $s[1];
}
var_dump( $cookie);
还有一些网站是以 set-cookie 响应,而不是Set-Cookie 这样的。所以程序还是有一些Bug,你可以自己去实现,不过我更推荐你使用 curl