【问题标题】:PHP + cURL + session idPHP + cURL + 会话 ID
【发布时间】:2014-01-02 15:01:54
【问题描述】:

在谷歌搜索了几个小时试图找到我的问题的答案后,我希望 SE 上的人能给我一个答案。

我正在尝试从网站解析一些 PDF 文件,URL 的格式如下所示:example.com/?s=ef6d225b80c0c590da26dcf1e37bc02c&t=2-1-2014%2013:24:25

我不知道如何从该 URL 获取会话 ID。

我尝试过这样的事情:

session_write_close();

$ch = curl_init($link); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt( $ch, CURLOPT_COOKIE, $strCookie ); 
$response = curl_exec($ch); 
curl_close($ch); 

ini_set("session.use_cookies",0);
ini_set("session.use_trans_sid",1);
session_id($_GET['session_id']);
print_r($_SESSION);
print(session_id());
But there is no output.

所以我需要将会话 ID 传递到 URL 中,但我不知道该怎么做。

感谢我能就这个问题获得的任何帮助。谢谢!

【问题讨论】:

  • $_GET 用于调用 YOUR 脚本的 url 中的查询字符串。它与从您通过 curl 从其他站点获取的数据中接收到的 urls/数据绝对 NOTHING 有任何关系。试试php.net/parse_url
  • 感谢您的评论!

标签: php session curl


【解决方案1】:

您可以从$link获取它:

if (preg_match('~s=([a-f0-9]{32})~', $link, $match)) {
    // got the session id in $match[1]
}

【讨论】:

  • 非常感谢,会努力的!
  • 所以我获取了 URL 并尝试使用 file_get_contents 打开 PDF,但它不起作用。我应该为此使用 cUrl 吗?这是代码: $html = file_get_html($baseURl . "/Acer-CR-6530/handleiding-5-100076.html'); // 查找所有链接 foreach($html->find('a[rel=nofollow ]') as $e) $link = $e->href; $link = $baseURL . $link; echo file_get_contents($link);
  • 对格式很抱歉,我是这个网站的新手,找不到 [code] 块的正确格式...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-03-06
  • 2012-06-23
  • 1970-01-01
  • 1970-01-01
  • 2019-10-12
  • 1970-01-01
  • 2017-03-01
相关资源
最近更新 更多