Today, We want to share with you session in php example for login and logout.In this post we will show you how to use session in php for login form with example?, hear for php simple login logout we will give you demo and example for implement.In this post, we will learn about registration and login form in php and mysql with an example.
PHP Login logout example with session
Create Database:
Create database pakainfo_app;
Create Database Table:
CREATE TABLE `employees` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `employee_nm` VARCHAR(255) NULL DEFAULT NULL, `employee_snm` VARCHAR(255) NULL DEFAULT NULL, `employee_mail_address` VARCHAR(255) NULL DEFAULT NULL, `phone` VARCHAR(255) NOT NULL, `password` VARCHAR(255) NULL DEFAULT NULL, `created` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) COLLATE='latin1_swedish_ci' ENGINE=InnoDB AUTO_INCREMENT=7 ;
Create Database Configuration file:
config.php
HTML Login Form:
index.php
PHP Login and Logout with Session - www.pakainfo.com
Style.css:
body{ font-family:verdana; background-color:#aaaae3; } .container{ width:40%; margin:10% auto; border:1px solid #eeeeee; background:#ffffff; } .container-dashboard{ width:90%; border:1px solid #eeeeee; background:#ffffff; padding:10px; } .field-container{ margin:10px auto; width:400px; } h1{ text-align:center; line-height:30px; font-size:24px; color:#061e5a; } label{ display:block; padding-bottom:5px; color:#F05519; font-weight:500; } input[type=email],input[type=password]{ border:1px solid #eeeeee; width:100%; height:30px; padding-left:4px; } button{ background:#061e5a; border:1px solid #061e5a; color:#ffffff; margin:10px 0px; padding:5px; } button:hover{ background:#F05519; border:1px solid #F05519; } .error-msg{ border:1px solid #ee0000; background:#ee0000; color:#ffffff; padding:2px; font-size:13px; } .success-msg{ border:1px solid #0ebc6f; background:#0ebc6f; color:#ffffff; font-size:13px; padding:2px; } .employee-name{ color:#ee0000; } .signout-link{ margin-top:10px; display:block; background:#061e5a; border:1px solid #061e5a; color:#ffffff; width:48px; padding:5px; text-decoration:none; font-size:13px; }
After Form Submit PHP Code:
index.php
After Successful Login:
Dashboard.php
Dashboard | PHP Login and logout example with session
Session Destroy:
signout.php
Error Message: (index.php)
index.php
"; echo $errorMsg; echo "