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.

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

报告相同问题?

悬赏问题

  • ¥66 比特币地址如何生成taproot地址
  • ¥20 数学建模数学建模需要
  • ¥15 关于#lua#的问题,请各位专家解答!
  • ¥15 什么设备可以研究OFDM的60GHz毫米波信道模型
  • ¥15 不知道是该怎么引用多个函数片段
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决