我有iframe,这将从不同的域访问。
例如:
Iframe - www.iframe.com
Domain1 - www.domain1.com
Domain2 - www.domain2.com`两个域都将使用不同的用户iframe访问iframe
问题是,当我访问domain1时,domain2中正在使用相同的会话。但我不想使用相同的,因为两个域将具有不同的用户i。
如何解决这个问题?
发布于 2017-11-13 17:57:35
我不确定你的目标是什么,但如果你给出更多细节,我会编辑答案。比方说。
域1 index.php
<?php
// here you have a specific userid
$userid = "user1";
// when you load the iframe, you send userid as parameter
?>
<iframe src="www.iframe.com?userid=<?php echo $userid; ?>"></iframe>域2 index.php
<?php
// the same thing, but different userid
$userid = "user2";
?>
<iframe src="www.iframe.com?userid=<?php echo $userid; ?>"></iframe>IFRAME index.php
<?php
// start session
session_start();
//let's say you already have a defined user structure in the SESSION
if (!isset($_SESSION["users"])) {
$_SESSION["users"] = array(
"user1" => array("name" => "USER 1"),
"user2" => array("name" => "USER 2")
);
}
// now, you can check the userid from the GET parameters to select the correct session
$userid = false;
if (isset($_GET["userid"]))
$userid = $_GET["userid"];
// check if user is valid
if ($userid && isset($_SESSION["users"][$userid])) {
// userid is valid
echo "Welcome ".$_SESSION["users"][$userid]["name"];
} else {
// userid is not valid
echo "Who are you, stranger?";
}注意:您必须确保用户以某种方式登录(使用密码验证用户,因为任何人都可以更改GET参数...)
https://stackoverflow.com/questions/47260949
复制相似问题