How To Login, Logout And Register Using Php, Html Forms, Sessions, – Login System Tutorial

How To Login, Logout And Register Using Php, Html, Css, Sessions, Forms – Login System Tutorial – Source Code

How To Login, Logout And Register Using Php, Html, Css, Sessions, Forms – Login System Tutorial

This tutorial shows how to login, logout and register using php, html, css, sql and mysql database. When you login the session is created and then the user is redirected to home page, where you can logout using logout button. What happens when you login is that, the script checks if your login credentials, matches with the user data stored in the database. If the user data is found in the database the you will be logged in. Else, the login process will fail. The created session is deleted or destroyed when you click logout button. Now after clicking the logout button the session is unset and you’re redirected to login page. That’s pretty much it about the login, logout and registration php system.


WEBSITE.PHP

<?php
session_start();
if(!isset($_SESSION&#91;'email'&#93;)) {
 header("location:login.php");
} else {
 $_SESSION&#91;'email'&#93;;
}
?>

<!DOCTYPE>
<html>
<head>
 <title>LOGIN LOGOUT REGISTER TUTORIAL SESSIONS PHP</title>
 <style type="text/css">
 #container {
  background-color: green;
  height: 1000px;
  width: 1000px;
  margin-right: auto;
  margin-left: auto;
 }

 #navigation {
  width: 1000px;
  background-color: black;
  height: 50px;
 }

 nav ul {
  padding: 0px;
  margin: 0px;
   }

nav ul li{
  list-style-type: none;
  float:left;
 }

nav ul li:last-child{
  float:right;
 }

nav ul li a{
 color:#ffffff;
 display: block;
 padding: 10px;
 text-decoration: none;
}

nav ul li a:hover{
 color:gray;
}

 </style>

</head>
<body>
 <div id="container">
  <div id="navigation">
  <nav>
       <ul>
        <li><a href="#"> Home </a></li>  
        <li><a href="logout.php"> logout </a></li>
        </ul>
       </nav>
   </div>
 </div>
</body>
</html>

REGISTER.PHP

<?php
session_start();
include("dbconn.php");
if(isset($_POST&#91;'submitdata'&#93;)) {
 $firstname = $_POST&#91;'firstname'&#93;;
 $email = $_POST&#91;'email'&#93;;
 $fileupload = $_FILES&#91;'fileupload'&#93;&#91;'name'&#93;;
 $fileuploadtmp = $_FILES&#91;'fileupload'&#93;&#91;'tmp_name'&#93;;
 $password = $_POST&#91;'password'&#93;;
 $folder = "images/";
move_uploaded_file($fileuploadtmp, $folder.$fileupload);
$insert = "INSERT INTO `regt`( `firstname`, `fileupload`, `email`, `password`) VALUES ('$firstname','$fileupload','$email','$password')";
$qry = mysqli_query($conn, $insert);
if($qry) {
     $_SESSION&#91;'email'&#93; = $email;
 header("location: website.php");
}
}
?>

<!DOCTYPE>
<html>
<head>
 <title>LOGIN LOGOUT REGISTER TUTORIAL SESSIONS PHP</title>
 <style type="text/css">
 #container {
  background-color: green;
  height: 1000px;
  width: 1000px;
  margin-right: auto;
  margin-left: auto;
 }
 #navigation {
  width: 1000px;
  background-color: black;
  height: 50px;
 }
 nav ul {
   padding: 0px;
  margin: 0px;
 }

nav ul li{
  list-style-type: none;
  float:left;
 }

nav ul li:last-child{
  float:right;
 }

nav ul li a{
 color:#ffffff;
 display: block;
 padding: 10px;
 text-decoration: none;
}

nav ul li a:hover{
 color:gray;
}

#formone {
 text-align: center;
 padding: 20px;
 margin: 10px;
}

#formone input[type="submit"], input[type="file"],input[type="text"], input[type="password"],input[type="email"] {
   padding:10px;
   width:190px;
}
 </style>
</head>
<body>
 <div id="container">
   <div id="navigation">  
   </div>
   <form action="" method="post" id= "formone" enctype="multipart/form-data">
 <input type="text" name="firstname"  placeholder="First Name"/><br /><br />
 <input type="file" name="fileupload"  /><br /><br />
 <input type="email" name="email"  placeholder ="Email"/><br /><br /> 
 <input type="password" name="password"  placeholder ="Password"/><br /><br />
 <input type="submit" name="submitdata"  />
 </form>
 </div>
</body>
</html>

DBCONN.PHP

<?php
$conn = mysqli_connect("localhost", "root", "", "loginlogoutregister");
if ($conn) {
 echo "connected";
}
?>

LOGIN.PHP

<?php
session_start();
include("dbconn.php");
if(isset($_POST&#91;'submitdatalogin'&#93;)) {
$email  = $_POST&#91;'email'&#93;;
$password  = $_POST&#91;'password'&#93;;
$sql = " SELECT * FROM `regt` WHERE `email` = '$email' ";
$qry = mysqli_query($conn, $sql);
while($row=mysqli_fetch_array($qry)) {
 $dbemail = $row&#91;'email'&#93;;
 $dbpassword = $row&#91;'password'&#93;;
 if ($email == $dbemail && $password == $dbpassword) {
         $_SESSION&#91;'email'&#93; = $email;
  header("location: website.php");
 }
}
}

?>

<!DOCTYPE>
<html>
<head>
 <title>LOGIN LOGOUT REGISTER TUTORIAL SESSIONS PHP</title>
 <style type="text/css">
 #container {
  background-color: green;
  height: 1000px;
  width: 1000px;
  margin-right: auto;
  margin-left: auto;
 }

#navigation {
  width: 1000px;
  background-color: black;
  height: 50px;
 }

 nav ul {
  padding: 0px;
  margin: 0px;
 }

nav ul li{
  list-style-type: none;
  float:left;
 }

nav ul li:last-child{
  float:right;
 }


nav ul li a{
 color:#ffffff;
 display: block;
 padding: 10px;
 text-decoration: none;
}

nav ul li a:hover{
 color:gray;
}

#formone {
 text-align: center;
 padding: 20px;
 margin: 10px;
}

#formone input[type="submit"], input[type="file"],input[type="text"], input[type="password"],input[type="email"] {
   padding:10px;
   width:190px;
}

 </style>
</head>
<body>

 <div id="container">
  <div id="navigation">
   </div>
   <form action="" method="post" id= "formone" enctype="multipart/form-data">
 <input type="email" name="email"  placeholder ="Email"/><br /><br />
 <input type="password" name="password"  placeholder ="Password"/><br /><br />
 <input type="submit" name="submitdatalogin"  />
 </form>
 </div>
</body>
</html>

LOGOUT.PHP

<?php
session_start();
session_unset($_SESSION&#91;'email'&#93;);
session_destroy();
header("location: login.php");
?>
How To Login, Logout And Register Using Php, Html, Css, Sessions, Forms – Login System Tutorial
How To Login, Logout And Register Using Php, Html, Css, Sessions, Forms – Login System Tutorial
How To Login, Logout And Register Using Php, Html, Css, Sessions, Forms – Login System Tutorial
How To Login, Logout And Register Using Php, Html, Css, Sessions, Forms – Login System Tutorial
READ MORE  Android Studio And Sqlite Database Tutorial Mobile Application Development (Crud) Create, Read, Update And Delete

Leave a Reply

Your email address will not be published. Required fields are marked *