douben7260 2016-11-20 06:12
浏览 48
已采纳

print_r怎么不在我的实时服务器上输出任何内容,但在我的本地主机上工作正常?

I'm building a web-application and currently testing out how to retrieve values from the server database and display it on my page. My connection to my database is working just fine.

In my localhost, I run the code print_r($_SESSION['user']; where $_SESSION['user'] stores the user's login session and it works fine. Here's what it outputs on my localhost:

Array([0]=>1 [1]=>Bob [2]=>Dylan [3]=>Bob.Dylan@gmail.com)

where Bob is the user's firstname, Dylan is his lastname, and Bob.Dylan@gmail.com is his email.

So that's all good.

But when it comes to my live server and I run the same print_r($_SESSION['user']; code again it displays absolutely nothing.

I'm eventually working my way to my objective of displaying all the related user's info on the database (basically, their profile page) so I thought I'd start with this and go from there but I can't even get the print_r function to work correctly.

Can anyone help me?

EDIT:

  • My connection to both my localhost and live server database is working fine

My code:

if(isset($_SESSION['user]))
{
     print_r($_SESSION['user']);
}
else
{
     echo "Session is not set" 
}
  • 写回答

4条回答 默认 最新

  • duanshang9426 2016-11-20 06:49
    关注

    It's probably falling under the else part. Your session may not have been set correctly.

    Try this:

    var_dump($_SESSION);  // Check your session variable
    
    if (isset($_SESSION['user'])) {
        print_r($_SESSION['user']);
    } else {
        echo "Session is not set"; 
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog