0

I'm from the Netherlands and my English isn't perfect, but I will try my best.

My problem is as followed: I've made a local website with Wampserver and everything worked fine on it, but now I've bought hosting and my SESSION variable doesn't work anymore.

The code of the function:

public function login($uname,$umail,$upass)
{
    try
    {
        $stmt = $this->db->prepare("SELECT * FROM users WHERE user_name=:uname OR user_email=:umail LIMIT 1");
        $stmt->execute(array(':uname'=>$uname, ':umail'=>$umail));
        $userRow=$stmt->fetch(PDO::FETCH_ASSOC);
        if($stmt->rowCount() > 0)
        {
            if(password_verify($upass, $userRow['user_pass']))
            {
                $_SESSION["user_session"] = $userRow['user_id'];
                return true;
            }
            else
            {
                return false;
            }
        }
    }
    catch(PDOException $e)
    {
        echo $e->getMessage();
    }
}

Code of the page where I try to check if someone is logged in:

        if(!$user->is_loggedin())
    {
        $user->redirect('login.php');
    }
$user_id = $_SESSION['user_session'];

And then the error I'm getting: Undefined index: user_session in /mnt/web515/b0/72/510494272/htdocs/admin/index.php on line 8

Can someone please help me figure out why user_session is undefined now but not when I locally run the website?

Thanks in advance!

S. Bos
  • 68
  • 11
  • Does your script run `session_start();` before you set `$_SESSION["user_session"]` ? You local environment might have been reliant on ` session.auto_start` – Scuzzy Apr 02 '20 at 22:31
  • Yes that's set correctly @Scuzzy – S. Bos Apr 02 '20 at 22:33
  • @Scuzzy the weird thing is that it works fine when using Wampserver, but not when I upload the same code to my webhost. – S. Bos Apr 02 '20 at 22:35
  • I don't have any further advice except to figure out what configuration is different between local and remote servers. my thought was locally the session was started automatically and that the session_start function wasn't being run, but you say its been set. – Scuzzy Apr 02 '20 at 23:03

0 Answers0