将 PHP 会话信息传递给 cURL


Passing PHP session info to cURL

我在站点和 cURL 请求之间传递会话数据时遇到问题。

代码:
此代码在 demo.xyz.com 上,它在 www.abc.com 时从数据库自动调用用户,并在成功登录的情况下创建一个会话变量 'SESSION_USER_ID'.
登录后,它使用 jQuery .load() 函数向 "www.abc.com/dashboard.php" 发起 cURL 请求。

$("#dash").load("get-rem-page.php?p=http://www.abc.com/dashboard.php").html("Loading...");

get-rem-page.php具有以下代码:

<?php
$url = $_REQUEST['p'];
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,$url);
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl_handle, CURLOPT_COOKIESESSION, true); 
curl_setopt($curl_handle, CURLOPT_COOKIE,session_name().'='.session_id());
curl_setopt($curl_handle, CURLOPT_COOKIEFILE, 'cookies.txt'); // set cookie file to given file 
curl_setopt($curl_handle, CURLOPT_COOKIEJAR, 'cookies.txt'); 

$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
if (empty($buffer))
{
    print "<p>Unable to load remote page</p>";
}
else
{
    print $buffer;
}
?>

仪表板的代码.php www.abc.com 如下:

<?php
session_start();
include "classes/local_info.php";
$objCon = new cD;
$objFun = new cF;
$link=$objCon->connectMYSQL();
$vCon = $objCon->connectDB($link);
if($vCon==false){
    echo "DB Error";
    exit;
}
echo "i am in dashboard.php & sessionid = ".$_SESSION["SESSION_USER_ID"]."<hr />";
$id = $_SESSION["SESSION_USER_ID"];
?>
<p>Welcome member number <?php echo $_SESSION["SESSION_USER_ID"];?></p>

DIV (id:dash) 中的输出为

我在仪表板中.php & sessionID =


欢迎会员

问题:
仪表板 .php 中的会话变量为空。需要传递此会话值,而不对仪表板.php进行任何更改。用CURLOPT_COOKIE尝试了大量的选择..但似乎没有一个奏效。需要专家开放。

我曾经经常玩卷曲和饼干,最终的工作代码是这样的:

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 5);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_VERBOSE, 0);
    curl_setopt($ch, CURLOPT_COOKIEJAR, session_name().'='.md5(session_id()));
    curl_setopt($ch, CURLOPT_COOKIE, session_name().'='.md5(session_id()));