Code:<\/strong><\/p>\n\n\n$username = $_POST['username'];\n$password = $_POST['pwd'];\nif($username == \"admin\" && $password == \"l0G3In\"){\nheader('location: Home.php');\n}\nelse {\n$error = \"Invalid username or password!\";\n}<\/pre>\nWith the above lines, once the user has submitted a valid set of credentials, he’s allowed access to home.php, or we store an error message which can be shown to the user.<\/p>\n
Session<\/h4>\n
We don’t want a user to repeatedly login in upon every request. Thus we need to keep track of users who have logged in, irrespective of the page they are requesting. One way of achieving this in PHP is using sessions.<\/p>\n
Briefly, sessions are a server-side small piece of information, temporarily stored for a client, once the page is requested. In PHP this is achieved by calling function session_start() as the first line in the script. From next time the page is accessed, session_start() doesn’t create a new session but retrieves information of the session started earlier and stores in a special array $_SESSION.<\/p>\n
Values to be passed across pages while a session is active can be set in a similar fashion to a normal array and isset() function can be used to check if a particular value is available within the array.<\/p>\n
Combining all the things discussed, the code will look as follows:<\/p>\n
Code:<\/strong><\/p>\n\n\nA sample login page<\/head>\n
\nEnter Login Information:<\/h2>
\n\n