【发布时间】:2014-12-15 09:41:42
【问题描述】:
我不能将 file_get_contents 与会话 cookie 一起使用!有 9 个 cookie.. 我的代码:
<?
$ip=explode('<a href="trade?t=',file_get_contents('http://csgolounge.com/'));
$ip=explode('">',$ip[1]);
$ip=$ip[0];
echo $ip;
$opts = array(
'http' => array(
'method' => 'GET',
'header' => 'Cookie: __utma=123\r\n__utmb=123\r\n__utmc=123\r\n__utmt=123\r\n__utmz=123\r\nid=123\r\nPHPSESSID=123\r\ntkz=123\r\ntoken=123\r\n'));
$context = stream_context_create($opts);
session_write_close();
$ip2=explode('<a class="buttonright" href="',file_get_contents('http://csgolounge.com/trade?t=' . $ip, false, $context)); // This doesn't return the url...
$ip2=explode('">Add on Steam</a>',$ip2[1]);
$ip2=$ip2[0];
echo $ip2;
?>
我做错了什么? 请帮忙!
【问题讨论】:
-
您能解释一下您要做什么吗?
-
试图从 csgolounge.com 获取 url (steam://friends/add/xxxxxxxxxxxxxxxxxxxx)
-
尝试使用像sourceforge.net/projects/simplehtmldom这样的html解析器
-
如果没有会话 cookie,我将无法解析...
-
当然可以,因为 file_gets_contents 返回可以解析的 html 字符串
标签: php session cookies file-get-contents