【问题标题】:PHP file_get_contents() and PHPSESSIDPHP file_get_contents() 和 PHPSESSID
【发布时间】: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


【解决方案1】:

Cookie 标头中的 Cookie 使用分号(不是换行符)分隔。

您的 Cookie 标头应如下所示:

'header' => 'Cookie: __utma=123; __utmb=123; __utmc=123; __utmt=123; __utmz=123; id=123; PHPSESSID=123; tkz=123; token=123'

【讨论】:

    猜你喜欢
    • 2014-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-28
    • 2019-06-05
    • 2014-08-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多