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 — checking whether a user is currently logged in

We'll need to be able to figure out if the profile a user is looking at is their own. So, let's add a variable to our view that tells us if that is the case.

  1. Open index.php, and add a variable called is_current_user that will determine if the profile that you are viewing is equal to the currently logged-in user.
    get('/user/:username', function($app) {
    $app->set('user', User::get_by_username($app- >request('username')));
    $app->set('is_current_user', ($app->request('username') == User::current_user() ? true : false));
    
    $app->render('user/profile');
    });
    
  2. Let's change the code in the header of views/user/profile.php so that we can output the user's full name as well as This is you!, if ...

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