dpj0015 2013-03-26 00:20
浏览 48

卷曲不通过phpsessid

Try as I might, I am unable to get curl to pass the PHPSESSID cookie. I have a similar setup to what several others have described, but I haven't been able to get any of the proposed solutions working.

I have a page that sends a get request to pageA.php. pageA.php needs some information from pageB.php, which is on another server, so I am using curl. pageB maintains the session state that I need to get to and from my page.

I am able to pass other cookies from pageA to pageB, just not the PHPSESSID cookie.

The following works (a cookie arrives on pageB):
$options[CURLOPT_COOKIE] = "myPHPSESSID=" . $sessionId;

The following does not:

$options[CURLOPT_COOKIE] =  "PHPSESSID=" . $sessionId;

(I build an $options array and then pass it to curl_set_opt_array)

In fact, the latter causes some sort of error that I am unable to discern, as my call to curl_exec never returns (and pageB is never reached).

I've tried setting the header instead of using CURLOPT_COOKIE, but also with no success:

$options[CURLOPT_HTTPHEADER][] = "Cookie: myPHPSESSID=" . $sessionId;

the above works just fine but

$options[CURLOPT_HTTPHEADER][] = "Cookie: PHPSESSID=" . $sessionId;

does not.

PHP evidently does not want me to manually set PHPSESSID. I'm not sure if it's relevant, but at no time on pageA do I call start_session() (though I tried doing so and had the same results).

I realize I could (probably) just pass the session id as a differently-named cookie and have pageB call set_session_id() or something similar. But I really want to know why what I'm doing is not working, as I'd rather fix what I'm doing wrong than create a workaround. I can provide some dumps of the various headers that are pinging around if that's helpful, but I figure this question is long enough for now.

Thanks...

  • 写回答

1条回答 默认 最新

  • drzablspw01655860 2013-03-26 19:04
    关注

    I'm facing the same problem. Found the solution.

    Call session_write_close(); before your curl_exec.

    This saved my life: http://kmak.1funkybit.com/?p=126 (read for explanation).

    Example:

    <?php
    session_start();
    var_dump($_SESSION); //See what's in session
    echo "<br>";
    
    
    
    $c = curl_init('http://192.168.100.204/logintest/index.php?r=AccessTest/CheckAcess');
    $parametros_post = 'action=verChau';
    curl_setopt($c, CURLOPT_POST, true);
    curl_setopt($c, CURLOPT_POSTFIELDS, $parametros_post);
    curl_setopt($c, CURLOPT_VERBOSE, TRUE);
    curl_setopt($c, CURLOPT_COOKIE, 'PHPSESSID=' . $_COOKIE['PHPSESSID']);
    curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
    session_write_close();
    $page = curl_exec ($c);
    echo "<br>";
    echo "<br>";
    echo $page;
    curl_close ($c);
    
    
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能