O'Reilly logo

CouchDB and PHP Web Development Beginner's Guide by Tim Juravich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – handling the current user

With most of the pieces of the puzzle in place, let's go through the process of changing the layout for users, depending on if they are logged in or not.

  1. Let's add a function called current_user in classes/user.php, so that we can retrieve the current user's username from the session.
    public static function current_user() {
    session_start();
    return $_SESSION['username'];
    session_write_close();
    }
    
  2. Add a public static function called is_authenticated into classes/user.php so we can see if the user is authenticated or not.
    public static function is_authenticated() {
    if (self::current_user()) {
    return true;
    } else {
    return false;
    }
    }
    
  3. Now that we have our authentication in order, let's tighten up the navigation ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required