$_SESSION values not holding!

前端 未结 5 631
轮回少年
轮回少年 2021-01-22 03:18

I\'m writing a user login system, and I (like so many others) am having a problem with my sessions.

Here\'s the pointer from the login script when the inputs are validat

相关标签:
5条回答
  • 2021-01-22 03:34

    Have you tried:

    print_r($_SESSION);

    to examine the contents of the session?

    0 讨论(0)
  • 2021-01-22 03:38

    use

    ob_start(); @session_start();

    on the top of the both page

    0 讨论(0)
  • 2021-01-22 03:43

    First of all, please enable debugging:

    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    

    Second, session_start() needs to be at the top of the page. So the line you wrote;

    You are logged in as: <?php echo session_start();$_SESSION['id']; ?>
    

    will never work.

    The following line needs to be on top of the page, before any HTML etc.

    <?php
    session_start();
    $id=$_SESSION['id'];
    ?>
    
    0 讨论(0)
  • 2021-01-22 03:59

    You're most likely running into output buffering, which is why it sometimes works and other times it does not. Generally speaking, stick to starting the session before any output is generated, you'll find your code works better.

    0 讨论(0)
  • 2021-01-22 04:01

    Make sure you're calling session_start() before you output anything on the page. The standard cookie-based sessions require some header information to be exchanged, which must be done before you send any content.

    0 讨论(0)
提交回复
热议问题