PHP + cURL +会话ID [英] PHP + cURL + session id

查看:121
本文介绍了PHP + cURL +会话ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

After googling for hours trying to find an answer for my problem I hope someone on SE can give me an answer.

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

I am trying to parse some PDF files from a website, the format of the URL looks like this: example.com/?s=ef6d225b80c0c590da26dcf1e37bc02c&t=2-1-2014%2013:24:25

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

I have no idea how I can fetch the session ID from this URL.

我尝试过类似的操作:

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,但我不知道该怎么做

So what I need the session ID to pass into the URL and I have no idea how to do this.

我很高兴能就此问题获得帮助。谢谢!

I appreciate any help I can get about this issue. Thanks!

推荐答案

您可以从 $ link 获取它:

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

这篇关于PHP + cURL +会话ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆