dongxuan1660
2014-12-18 14:05
采纳率: 100%
浏览 19
已采纳

会话中的php user_id无法正常工作

i need some help about $_session. My team have develop an Web-Application and there are a problem that i cannot get the user_id on the $_session['user_id']? on the mailing view:

 if(isset($_SESSION['user_id'])&&$_SESSION['angemeldet']){

    $objModel = new MAILING();
    $id=$_SESSION['user_id'];

and on the login part:

if ($login_success) {
    //die();
    $_SESSION['angemeldet'] = true;
    $_SESSION['user_email'] = $login_success['user_email'];
    $_SESSION['user_role'] = $login_success['role'];
    $_SESSION['user_id'] = $login_success['user_id'];
    if ($login_success['role'] == 'admin'){
       header('Location: ?page=admin');
    }else{
       header('Location: ?page=home');
    }

}

the problem that if i try the codes on localhost, it work perfectly and on the server $_SESSION['user_id'] is somehow like empty??

could someone help me? thx b4.

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanmu5641 2014-12-18 15:06
    已采纳

    As suggested in the comments I would check if you have enabled sessions on your server environment. See the answer by answer by Adarsh here: PHP.ini example to enable sessions?

    Also, it can be useful to print out and debug you varialbes along the way to see where you lose your data/information. Try using the print_r() function for debuging. Try using print_r($login_success); print_r($_SESSION); exit(); after you have set your variables to print out all of the variables data.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题