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 – adding functionality for users to log out

I bet you thought the login script was pretty easy. Wait until you see how easy it is for us to allow users to log out.

  1. Open classes/user.php, and create a public static function called logout.
    public static function logout() {
    $bones = new Bones();
    $bones->couch->login(null, null);
    session_start();
    session_destroy();
    }
    
  2. Add a route into the index.php file, and have it call the logout function.
    get('/logout', function($app) {
    User::logout();
    $app->redirect('/');
    });
    
  3. Notice that we are calling a new feature inside of Bones a redirect function. In order for this to work, let's add a quick new function at the bottom of our
    public function redirect($path = '/') { header('Location: ' . $this->make_route($path)); ...

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