dongxuan1660 2014-12-18 06: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 07: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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部