0

Php session doesn't work... can anyone tell me what I'm doing wrong.

if (crypt($_POST["password"], $row["password"]) == $row["password"])
                        {
                            // remember that user's now logged in by storing user's ID in session
                            $_SESSION["id"] = $row["email"];
                            $_SESSION["firstname"] = $row["firstname"];
                            echo json_encode(array('auth' => 'true'));
                        }
                        else{
                           echo json_encode(array('auth' => 'false', 'error' => 'Invalid Username or Password'));
                        }
  • Did you add `session_start()` at the top of the page? – iamgory Jan 25 '16 at 15:00
  • yes I did just after php – Stive Hassan Jan 25 '16 at 15:02
  • 1
    Please use PHP's [built-in functions](http://jayblanchard.net/proper_password_hashing_with_PHP.html) to handle password security. If you're using a PHP version less than 5.5 you can use the `password_hash()` [compatibility pack](https://github.com/ircmaxell/password_compat). – Jay Blanchard Jan 25 '16 at 15:09
  • Use var_dump($_SESSION) to check for your session array and see if there is anything unusual. – sensation Jan 25 '16 at 15:42

0 Answers0