-2

I have a PHP user authentication script, but it isn't functioning properly. I am trying to perform the following:

  1. Return to login page if the session variable "expires" is in the past, or if the user is neither an administrator, nor is logged in.
  2. Else set the session variable "expires" to time() + 300 and redirect to the home page.

    $case1 = (isset($_SESSION["expires"]) && $_SESSION["expires"] > time());
    $case2 = ($_SESSION["user_id"] == "ADMIN" || $_SESSION["user_id"] != "");
    $case3 = (isset($_SESSION["user_id"]) && (case2));
    
    if (case1 || case3) {
        // redirect to home page
    }
    else // redirect to login page
    
  • Why do you check if `isset($_SESSION["user_id"])` *after* you have actually used it on the line before? – Eggplant May 04 '15 at 14:34
  • [**Undefined constants**, that's what you should be getting had you been using error reporting.](http://php.net/manual/en/function.error-reporting.php) – Funk Forty Niner May 04 '15 at 14:34
  • Sorry, this is my first post on Stack Overflow and I had trouble with the directions for posting code. I have the proper variable sign "$" on my actual script. – user4816830 May 05 '15 at 11:46

1 Answers1

2
if (case1 || case3) {

Should be

if ($case1 || $case3) {

Also

$case3 = (isset($_SESSION["user_id"]) && (case2));

case 2 should also start with a $

$case3 = (isset($_SESSION["user_id"]) && ($case2));

Just like when a variable is created, when using a variable, it should start with a $

  • 2
    And the other case2 above that should be $case2. All variables begin with $. – kainaw May 04 '15 at 14:34
  • 1
    *"should also start with a $"* - [Otherwise....](http://stackoverflow.com/questions/30032780/user-authentication-not-working#comment48181718_30032780) – Funk Forty Niner May 04 '15 at 14:38