O'Reilly logo

PHP and MongoDB Web Development by Rubayeet Islam

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 - creating the login, logout, and profile page

The login page will show a form where the user can type in the username and password. If he/she is authenticated, he/she will be redirected to his/her profile page. The profile page will show his/her basic information and can only be accessed when he/she is logged in. The user can log out by clicking on the link on the profile page.

  1. Create a new file named login.php with the following code:
    <?php $action = (!empty($_POST['login']) && ($_POST['login'] === 'Log in')) ? 'login' : 'show_form'; switch($action) { case 'login': require('session.php'); require('user.php'); $user = new User(); $username = $_POST['username']; $password = $_POST['password']; if ($user->authenticate($username, ...

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