iframe 使用不同的 sessionid
我的其中一个页面上有一个 iframe,它显示了一个计时器。重要的是,当会话结束并且用户回来时,计时器必须再次从 0 开始。这是行不通的,经过故障排除后,我意识到我的 Iframe 比其他页面有另一个 sessionid。因此,如果用户注销并返回,Iframe 会继续使用之前的 sessionid。我做错了什么,如何让我的 Iframe 不使用它自己的会话 ID?所以总结一下timer.php(Iframe页面/第二页),session_id()在注销和返回时保持不变。我需要它使用与page1相同的会话信息,而不是它自己的。我希望我解释正确。
PAGE1
if ($_SESSION['auth']) {
include 'datalogin.php';
$sessionId = session_id();
$tid = $_SESSION['tid'];
$userid = $_SESSION['userid'];
echo "<IFRAME SRC='timer.php?tid=$tid&userid=$userid' WIDTH='100' HEIGHT='50' frameborder='0'></IFRAME>";
TIMPER.PHP
<?php
header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
session_start();
?>
<head>
<meta http-equiv="Refresh" content="1; ">
</head>
<body>
<?php
session_start();
$sessionId = session_id();
echo $sessionId;
I've got an iframe on 1 of my pages which displays a timer. It is important that when te session ends and the user comes back the timer must start from 0 again. This is not working, after troubleshooting I've realized that my Iframe has another sessionid than my other pages. So if the user logs out and comes back the Iframe continues with the previous sessionid. What am I doing wrong, how do I get my Iframe to not use it's own session id? So just to sum it up on timer.php (the Iframe page/2nd page) the session_id() stays the same when logged out and coming back in. I need it to use the same session information as page1, not it's own. I hope I explained correctly.
PAGE1
if ($_SESSION['auth']) {
include 'datalogin.php';
$sessionId = session_id();
$tid = $_SESSION['tid'];
$userid = $_SESSION['userid'];
echo "<IFRAME SRC='timer.php?tid=$tid&userid=$userid' WIDTH='100' HEIGHT='50' frameborder='0'></IFRAME>";
TIMPER.PHP
<?php
header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
session_start();
?>
<head>
<meta http-equiv="Refresh" content="1; ">
</head>
<body>
<?php
session_start();
$sessionId = session_id();
echo $sessionId;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案#1:你可以使用(jquery)ajax而不是iframe(这可能无法解决你的问题,我真的不知道你为什么使用iframe)
解决方案#2:你尝试过使用session_name('YOUR_SESSION_NAME_HERE');在使用 session_start() 后的每个页面上; ?
解决方案#3:您可以将 php 会话 id 作为 GET 参数 (timer.php?tid=$tid&userid=$userid&sess=" . session_id()) 传递到您的 iframe (据我所知这不是所以安全,无论如何可以是自定义情况下的解决方案)然后你只需在 session_start(); 之后执行 session_id($_GET['sess']);
solution #1: you can just use (jquery) ajax instead of iframe (that may not solve your issue, I don't really know why are you using iframe)
solution #2: have you tried using session_name('YOUR_SESSION_NAME_HERE'); on each page after using session_start(); ?
solution #3: you can just pass the php session id as a GET parameter (timer.php?tid=$tid&userid=$userid&sess=" . session_id()) to your iframe (as far as I know that's not so secure, anyway can be a solution in custom cases) then you just do session_id($_GET['sess']); after session_start();