php session doesn't work

前端 未结 8 514
余生分开走
余生分开走 2021-01-22 18:57

How it should work: Index.php is the secured page. It includes check.php, which checks if you have a session = good. If it hasn\'t, you\'re not logged in -> log off, remove sess

相关标签:
8条回答
  • 2021-01-22 19:05
    if($count==1){
        session_start();    
        $_SESSION['Username'] = $UserName;
        $_SESSION['Password'] = $password;
        UpdateOnlineChecker($Session);
        header( "Location: http://". strip_tags( $_SERVER ['HTTP_HOST'] ) ."/newHolo/" );
        exit;
    }
    else {
        echo "Wrong Username or Password";
    }
    

    Look at my code. It checks if the statement is true (for me, if there is one row with a query statement i execute). Then i start a session and basically Ill define global session variables, sned out a query to my database to update the session and then refer through.

    you are missing a session_start(); in your if true block.

    0 讨论(0)
  • 2021-01-22 19:08

    Use one for action document such as index.php there is code:

    session_start();
    if(isset($_POST['login']) && isset($_POST['password'])){
       // login
       header('Location: (here is some page)');
    }
    if(!isset($_SESSION['user']){
      // @todo some action
    } else {
      require_once('login.php');
    }
    
    if(isset($_GET['logout'])){
       unset($_SESSION['user']);
       header('Location: (here is some page)');
    }
    
    0 讨论(0)
  • 2021-01-22 19:17

    I think problem is header:

    ('location:------.php);
    

    Your hosting server doesn't run this. You can use this:

    echo "<script>window.location.href='-----.php'</script>";
    
    0 讨论(0)
  • 2021-01-22 19:22

    Check that you have register_globals is On in your php.ini

    0 讨论(0)
  • 2021-01-22 19:24

    First check on the pages you want to use session variables session is start or not and if session is not stat then start it.

    and this is the very first line in the php file.

    Code for the session checking is :

    if(!session_id())
    {
        session_start();
    }
    
    0 讨论(0)
  • 2021-01-22 19:26

    You need to have session_start() at the top of all the pages, you havent shown the session start for your login page.

    (Thanks to Danny for proving I cant type)

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