Session in Php Example for Login and Logout Without Database Updated FREE

Session in Php Example for Login and Logout Without Database

  • Updated appointment Jun fifteen, 2020
  • one.4m
  • 32

This commodity shows how to make a login, logout and view script using PHP, MySQL and Twitter Bootstrap.

Introduction

I am assuming here that y'all are familiar with HTML and CSS. I accept commented the code with the necessary information in the major role of the code. And so you can understand easily. I take also attached the source code then you can download it and use it. Allow'south kickoff.

Note

I have posted this PHP Registration Script on my personal blog. Y'all can also check information technology.

The following are the points we will be learning in this article,

  1. Creating a Database in PHPMyAdmin.
  2. Create a connection with the MySQL database.
  3. Insert, delete, and view information from MySQL database.
  4. Some Bootstrap components.
  5. Sessions in PHP.

Files and IDE

  1. Registration
  2. Login
  3. Logout
  4. Welcome
  5. Admin_login
  6. View_users
  7. Db_conection
  8. Delete.php

I am using PHPStorm for the coding and Bootstrap framework for forepart development.

Create Database

Create Database

Create Tables

Create table

Create columns in the Users table

Create columns

Crate Admin Table

Admin Table

Create Admin Columns

create admin column

Registration.php

  1. <html>
  2. <head lang="en" >
  3.     <meta charset="UTF-viii" >
  4.     <link blazon="text/css"  rel= "stylesheet"  href= "bootstrap-three.2.0-dist\css\bootstrap.css" >
  5.     <title>Registration</title>
  6. </head>
  7. <mode>
  8.     .login-console {
  9.         margin-top: 150px;
  10. </fashion>
  11. <body>
  12. <divclass = "container" ><!-- container class  is used to centered  the body of the browser with  some decent width-->
  13.     <divclass = "row" ><!-- row class  is used for  grid system in  Bootstrap-->
  14.         <divcourse = "col-md-4 col-md-offset-4" ><!--col-medico-4 is used to create the no of colums in  the grid also employ for  medimum and large devices-->
  15.             <divgrade = "login-panel panel panel-success" >
  16.                 <divform = "console-heading" >
  17.                     <h3grade = "console-championship" >Registration</h3>
  18.                 </div>
  19.                 <divclass = "panel-body" >
  20.                     <grade role="form"  method= "postal service"  activity= "registration.php" >
  21.                         <fieldset>
  22.                             <divcourse = "class-group" >
  23.                                 <inputclass = "form-control"  placeholder= "Username"  proper name= "name"  type= "text"  autofocus>
  24.                             </div>
  25.                             <divclass = "form-group" >
  26.                                 <inputclass = "form-command"  placeholder= "Eastward-post"  name= "email"  type= "email"  autofocus>
  27.                             </div>
  28.                             <divclass = "grade-group" >
  29.                                 <inputclass = "form-command"  placeholder= "Password"  name= "pass"  type= "countersign"  value= "" >
  30.                             </div>
  31.                             <inputform = "btn btn-lg btn-success btn-block"  blazon= "submit"  value= "annals"  name= "annals"  >
  32.                         </fieldset>
  33.                     </form>
  34.                     <center><b>Already registered ?</b> <br></b><a href="login.php" >Login here</a></middle><!-- for  centered text-->
  35.                 </div>
  36.             </div>
  37.         </div>
  38.     </div>
  39. </div>
  40. </torso>
  41. </html>
  42. <?php
  43. include("database/db_conection.php" );
  44. if (isset($_POST[ 'register' ]))
  45. {
  46.     $user_name=$_POST['proper noun' ];
  47.     $user_pass=$_POST['pass' ];
  48.     $user_email=$_POST['email' ];
  49. if ($user_name== '' )
  50.     {
  51.         echo"<script>alert('Please enter the proper noun')</script>" ;
  52. get out();
  53.     }
  54. if ($user_pass== '' )
  55.     {
  56.         repeat"<script>alert('Please enter the password')</script>" ;
  57. exit();
  58.     }
  59. if ($user_email== '' )
  60.     {
  61.         echo"<script>alert('Please enter the e-mail')</script>" ;
  62.     exit();
  63.     }
  64.     $check_email_query="select * from users WHERE user_email='$user_email'" ;
  65.     $run_query=mysqli_query($dbcon,$check_email_query);
  66. if (mysqli_num_rows($run_query)>0)
  67.     {
  68. echo"<script>warning('Email $user_email is already exist in our database, Please endeavour another ane!')</script>" ;
  69. go out();
  70.     }
  71.     $insert_user="insert into users (user_name,user_pass,user_email) VALUE ('$user_name','$user_pass','$user_email')" ;
  72. if (mysqli_query($dbcon,$insert_user))
  73.     {
  74.         echo"<script>window.open('welcome.php','_self')</script>" ;
  75.     }
  76. }
  77. ?>

register

Login.php

  1. <?php
  2. session_start();
  3. ?>
  4. <html>
  5. <caput lang="en" >
  6.     <meta charset="UTF-8" >
  7.     <link type="text/css"  rel= "stylesheet"  href= "bootstrap-3.two.0-dist\css\bootstrap.css" >
  8.     <title>Login</title>
  9. </head>
  10. <manner>
  11.     .login-panel {
  12.         margin-summit: 150px;
  13. </style>
  14. <trunk>
  15. <divcourse = "container" >
  16.     <divclass = "row" >
  17.         <divform = "col-md-4 col-doctor-starting time-4" >
  18.             <divclass = "login-panel panel console-success" >
  19.                 <divgrade = "console-heading" >
  20.                     <h3class = "panel-championship" >Sign In</h3>
  21.                 </div>
  22.                 <divclass = "console-body" >
  23.                     <form office="form"  method= "post"  activity= "login.php" >
  24.                         <fieldset>
  25.                             <divclass = "form-group"   >
  26.                                 <inputgrade = "course-control"  placeholder= "E-postal service"  name= "email"  blazon= "email"  autofocus>
  27.                             </div>
  28.                             <divcourse = "form-grouping" >
  29.                                 <inputclass = "course-control"  placeholder= "Password"  name= "laissez passer"  type= "password"  value= "" >
  30.                             </div>
  31.                                 <inputclass = "btn btn-lg btn-success btn-block"  type= "submit"  value= "login"  name= "login"  >
  32.                             <!-- Modify this to a push buttonor  input when using this equally  a form -->
  33.                           <!--  <a href="index.html" class = "btn btn-lg btn-success btn-block" >Login</a> -->
  34.                         </fieldset>
  35.                     </form>
  36.                 </div>
  37.             </div>
  38.         </div>
  39.     </div>
  40. </div>
  41. </torso>
  42. </html>
  43. <?php
  44. include ( "database/db_conection.php" );
  45. if (isset( $_POST [ 'login' ]))
  46. {
  47. $user_email = $_POST [ 'email' ];
  48. $user_pass = $_POST [ 'pass' ];
  49. $check_user = "select * from users WHERE user_email='$user_email'AND user_pass='$user_pass'" ;
  50. $run =mysqli_query( $dbcon , $check_user );
  51. if (mysqli_num_rows( $run ))
  52.     {
  53. echo "<script>window.open('welcome.php','_self')</script>" ;
  54. $_SESSION [ 'e-mail' ]= $user_email ;
  55.     }
  56. else
  57.     {
  58. echo "<script>alert('Electronic mail or password is incorrect!')</script>" ;
  59.     }
  60. }
  61. ?>

login

Logout.php

  1. <?php
  2. session_start();
  3. session_destroy();
  4. header("Location: login.php" );
  5. ?>

Welcome.php

  1. <?php
  2. session_start();
  3. if (! $_SESSION [ 'email' ])
  4. {
  5.     header("Location: login.php" );
  6. }
  7. ?>
  8. <html>
  9. <head>
  10.     <title>
  11.         Registration
  12.     </title>
  13. </head>
  14. <torso>
  15. <h1>Welcome</h1><br>
  16. <?php
  17. echo $_SESSION [ 'email' ];
  18. ?>
  19. <h1><a href="logout.php" >Logout hither</a> </h1>
  20. </torso>
  21. </html>

Admin_login.php

  1. <html>
  2. <head lang="en" >
  3.     <meta charset="UTF-viii" >
  4.     <link type="text/css"  rel= "stylesheet"  href= "bootstrap-3.two.0-dist\css\bootstrap.css" >
  5.     <title>Admin Login</title>
  6. </head>
  7. <style>
  8.     .login-panel {
  9.         margin-acme: 150px;
  10. </style>
  11. <body>
  12. <divclass = "container" >
  13.     <divclass = "row" >
  14.         <divclass = "col-doctor-four col-md-offset-4" >
  15.             <divform = "login-panel panel panel-success" >
  16.                 <divclass = "panel-heading" >
  17.                     <h3grade = "panel-title" >Sign In</h3>
  18.                 </div>
  19.                 <divcourse = "panel-torso" >
  20.                     <form role="form"  method= "postal service"  activity= "admin_login.php" >
  21.                         <fieldset>
  22.                             <divcourse = "form-group"   >
  23.                                 <inputclass = "form-control"  placeholder= "Name"  proper noun= "admin_name"  blazon= "text"  autofocus>
  24.                             </div>
  25.                             <divclass = "form-group" >
  26.                                 <inputclass = "class-control"  placeholder= "Password"  name= "admin_pass"  type= "password"  value= "" >
  27.                             </div>
  28.                             <inputclass = "btn btn-lg btn-success btn-block"  type= "submit"  value= "login"  proper noun= "admin_login"  >
  29.                         </fieldset>
  30.                     </grade>
  31.                 </div>
  32.             </div>
  33.         </div>
  34.     </div>
  35. </div>
  36. </body>
  37. </html>
  38. <?php
  39. include("database/db_conection.php" );
  40. if (isset($_POST[ 'admin_login' ]))
  41. {
  42.     $admin_name=$_POST['admin_name' ];
  43.     $admin_pass=$_POST['admin_pass' ];
  44.     $admin_query="select * from admin where admin_name='$admin_name' AND admin_pass='$admin_pass'" ;
  45.     $run_query=mysqli_query($dbcon,$admin_query);
  46. if (mysqli_num_rows($run_query)>0)
  47.     {
  48.         echo"<script>window.open('view_users.php','_self')</script>" ;
  49.     }
  50. else  {echo "<script>alarm('Admin Details are incorrect..!')</script>" ;}
  51. }
  52. ?>

View_users.php

  1. <html>
  2. <head lang="en" >
  3.     <meta charset="UTF-8" >
  4.     <link blazon="text/css"  rel= "stylesheet"  href= "bootstrap-three.2.0-dist\css\bootstrap.css" > <!--css file link in  bootstrap binder-->
  5.     <title>View Users</championship>
  6. </head>
  7. <style>
  8.     .login-panel {
  9.         margin-elevation: 150px;
  10.     }
  11.     .tabular array {
  12.         margin-acme: 50px;
  13. }
  14. </style>
  15. <torso>
  16. <divform = "tabular array-scrol" >
  17.     <h1 align="center" >All the Users</h1>
  18. <divform = "tabular array-responsive" ><!-- this  is used for  responsive display in  mobile and other devices-->
  19.     <tableclass = "table table-bordered table-hover table-striped"  style= "table-layout: fixed" >
  20.         <thead>
  21.         <tr>
  22.             <th>User Id</thursday>
  23.             <thursday>User Name</th>
  24.             <th>User E-mail</th>
  25.             <thursday>User Laissez passer</th>
  26.             <th>Delete User</thursday>
  27.         </tr>
  28.         </thead>
  29.         <?php
  30.         include("database/db_conection.php" );
  31.         $view_users_query="select * from users" ;
  32.         $run=mysqli_query($dbcon,$view_users_query);
  33. while ($row=mysqli_fetch_array($run))
  34.         {
  35.             $user_id=$row[0];
  36.             $user_name=$row[1];
  37.             $user_email=$row[2];
  38.             $user_pass=$row[3];
  39.         ?>
  40.         <tr>
  41. <!--hither showing resultsin  the tabular array -->
  42.             <td><?php echo $user_id;  ?></td>
  43.             <td><?php repeat $user_name;  ?></td>
  44.             <td><?php echo $user_email;  ?></td>
  45.             <td><?php echo $user_pass;  ?></td>
  46.             <td><a href="delete.php?del=<?php echo $user_id ?>" ><button class = "btn btn-danger" >Delete</push></a></td> <!--btn btn-danger is a bootstrap push button to show danger-->
  47.         </tr>
  48.         <?php } ?>
  49.     </table>
  50.         </div>
  51. </div>
  52. </trunk>
  53. </html>

user status

Db_conection.php

  1. <?php
  2. $dbcon =mysqli_connect( "localhost" , "root" , "" );
  3. mysqli_select_db($dbcon , "users" );
  4. ?>

Delete.php

  1. <?php
  2. include ( "database/db_conection.php" );
  3. $delete_id = $_GET [ 'del' ];
  4. $delete_query = "delete  from users WHERE id='$delete_id'" ;
  5. $run =mysqli_query( $dbcon , $delete_query );
  6. if ( $run )
  7. {
  8. echo "<script>window.open('view_users.php?deleted=user has been deleted','_self')</script>" ;
  9. }
  10. ?>

Session in Php Example for Login and Logout Without Database

DOWNLOAD HERE

Source: https://www.c-sharpcorner.com/UploadFile/9582c9/script-for-login-logout-and-view-using-php-mysql-and-boots/

Posted by: rowdenlayse1997.blogspot.com

Comments