跨域会话共享PHP

时间:2016-05-03 23:06:45

标签: php session curl

我已经看到其他人就同一问题提出的一些问题,但我的情况似乎没有太多运气,并希望得到一些澄清。

我需要将会话变量从domain1.com传递到domain2.com。我可以完全访问这两个域。我正在使用cURL domain1.com/caller.php访问domain2.com/receiver.php。一旦cURL完成执行,我就会返回一个状态。如果状态良好,我会使用header("Location: auto_submit.html")加载自动提交表单/重定向到domain2.com/test.php的页面。但是,当页面加载时,未设置会话变量。这是domain1.com/caller.php中的内容

...
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "domain2.com/receiver.php");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $result[0]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER , true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/cookies.txt');
$curl_result = json_decode(curl_exec($ch));
curl_close($ch);
if ($curl_result->status === 1)
{
    header("Location: ./auto_submit.html");
    exit;
} else {
    foo();
}
...

auto_submit.html只是重定向到domain2.com/test.phpdomain2.com/test.php我需要什么,以便它可以使用Cookie文件中的信息,并且可以$_SESSION访问?

0 个答案:

没有答案