Authentication
It is very common to track and store user information in cookies; however, since cookies are stored on the client side, we will use sessions for storing user information and making it available across the web application after authenticating the users. We will still use authentication for determining whether the submitted data is valid. Upon authentication, we will load the required user information into session variables and use that information wherever required. For building authentication for our student portal, let us begin by creating our library files to support the authentication.
Create the lib/Session.php
file with the following code:
<?php class Session { public static function init() { session_start(); } public static function destroy() { session_destroy(); } }
In this snippet, we begin creating the Session
library that contains two methods, init
and destroy
. The init
and destroy
functions use the session_start
and session_destroy
functions...