Jump to content

Why aren't these sessions set...


TeddyKiller

Recommended Posts

This is part a class, the login logs in correctly, well put it this way.. it redirects to the main page. So in the login function, its returning true. (FACT)

 

Although on the checkLogin, it doesn't get the $_SESSION['uid'] and $_SESSION['hash']

I echo'd them and.. well, they aren't set.

 

Whats going on? Thanks.

    /* Session::checkLogin() - Checks if the user has already logged in */
    function checkLogin() {
        if (isset($_COOKIE['HORBLECOOKIE'])) :
            $data = explode('-', $_COOKIE['HORBLECOOKIE']);
            $_SESSION['uid'] = $data[1];
            $_SESSION['hash'] = $data[0];
        endif;
        
        if (isset($_SESSION['uid']) && isset($_SESSION['hash'])) {
        
            if (User::confirmUserID($_SESSION['uid']) != 0) {
                session_unset();
                return false;
            }
            
            return true;
            
        } else {

            return false;
            
        }
    }
      
      
      
    /* Session::login() - Effectively logging in the user */
    function login($uname, $upass, $keeplogged) {
        global $msgError;
          global $secret_key;
          
        if (empty($uname) || strlen($uname = trim($uname)) == 0 || empty($upass)) {
            $msgError = "<span>Error!</span> You have left empty fields!.";
            return;
        }
          
        $uname = clean($uname, 1, 0, 2);
        $upass = clean($upass, 1 , 0, 0);
        $result = User::confirmUserPass($uname, $upass);
        
        if ($result == 0 || $result == 2) {
            $msgError = "<span>Error!</span> Please enter valid username and password.";
            return;
        } elseif ($result == 3) {
            $msgError = "<span>Error!</span> Your user account has not been activated yet!";
            return;
        }
          
        if (empty($msgError)) {
            $this->userinfo = User::getUserInfo($uname);
            $this->id = $_SESSION['uid'] = $this->userinfo['id'];
            $_SESSION['hash'] = sha1($_SESSION['uid'] . $_SERVER['REMOTE_ADDR'] . $secret_key);
              
            User::updateUserField($this->username, "last_login", $this->time);
            User::updateUserField($this->username, "ip", $_SERVER['REMOTE_ADDR']);
              
            if ($keeplogged) {
                setcookie("HORBLECOOKIE", $_SESSION['hash'].'-'.$this->id, $this->time + COOKIE_EXPIRE);
            }
            
            return true; //It gets to here, and it does return
        } else {
            return false;
        }
    }

 

These aren't being set for some reason. Not quite sure why.

$this->id = $_SESSION['uid'] = $this->userinfo['id'];

$_SESSION['hash'] = sha1($_SESSION['uid'] . $_SERVER['REMOTE_ADDR'] . $secret_key);

I made the login return false, and I echo'd them. It echo's it out.

 

Above the check login, is a startSession. This calls the check login, so it must be starting the session?

    function startSession() {
        session_start();
          
        $this->logged_in = $this->checkLogin();
    }

This function is called from within a __construct function. Though like I say, it calls the checklogin, so..

 

I'm puzzled to why it doesn't work?

Link to comment
https://forums.phpfreaks.com/topic/201319-why-arent-these-sessions-set/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.