doujuanju3076 2012-11-20 18:07 采纳率: 0%
浏览 20
已采纳

跨页面的PHP会话

have this question in mind. I know there are a lot questions like this on the internet, but none of them seem to do the trick for me :(

So I'm planning on making an adminpanel on a website. You enter by going through a login screen, when the name+pass is correct an session is made. On the other adminpages I'll test if this session is set, by this I'll know if the user can access the page or not.

Inlog.php (simplyfied)

<?php session_start(); ?> <html ...

then after lots of controls

    if ($adminpwd == $pass) {
    session_regenerate_id();
    $_SESSION["mysessionname"] = $name;
    $tijd = date('H:i:s', strtotime('+ 30 minutes'));
    $_SESSION["E4A_einde"] = $tijd;
    session_write_close();
echo "<script type='text/javascript'>window.location = 'myotheradminpage'</script>";
}

My other php pages include this script

<?php session_start();
if (!isset($_SESSION["mysessionname"])) {

session_destroy();
echo '<SCRIPT LANGUAGE="JavaScript"> window.alert("no session found") </SCRIPT>';
echo "<script type='text/javascript'>window.location = 'myloginpage'</script>";
        }

With this element, if the session is not set there's a redirect, if the session is set the other code on the php page wil be triggered.

But the fact is that Every single time i'm redirected again to my loginpage. so my session is not set :s Can't figure out why so please help me out.

I tried a lot of thins with on every page to add the session_start() methode, I tried to regenerated the session id before I set the sessions, but nothing works..

  • 写回答

2条回答 默认 最新

  • drz49609 2012-11-20 18:13
    关注

    In your initial session_start before the HTML, try setting this:

    <?php session_start();  
    $_SESSION["mysessionname"]; ?>
    <html ...
    

    This will declare your session variable before anything runs.

    Let me know if this works.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度