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,
- Creating a Database in PHPMyAdmin.
- Create a connection with the MySQL database.
- Insert, delete, and view information from MySQL database.
- Some Bootstrap components.
- Sessions in PHP.
Files and IDE
- Registration
- Login
- Logout
- Welcome
- Admin_login
- View_users
- Db_conection
- Delete.php
I am using PHPStorm for the coding and Bootstrap framework for forepart development.
Create Database
Create Tables
Create columns in the Users table
Crate Admin Table
Create Admin Columns
Registration.php
- <html>
- <head lang="en" >
- <meta charset="UTF-viii" >
- <link blazon="text/css" rel= "stylesheet" href= "bootstrap-three.2.0-dist\css\bootstrap.css" >
- <title>Registration</title>
- </head>
- <mode>
- .login-console {
- margin-top: 150px;
- </fashion>
- <body>
- <divclass = "container" ><!-- container class is used to centered the body of the browser with some decent width-->
- <divclass = "row" ><!-- row class is used for grid system in Bootstrap-->
- <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-->
- <divgrade = "login-panel panel panel-success" >
- <divform = "console-heading" >
- <h3grade = "console-championship" >Registration</h3>
- </div>
- <divclass = "panel-body" >
- <grade role="form" method= "postal service" activity= "registration.php" >
- <fieldset>
- <divcourse = "class-group" >
- <inputclass = "form-control" placeholder= "Username" proper name= "name" type= "text" autofocus>
- </div>
- <divclass = "form-group" >
- <inputclass = "form-command" placeholder= "Eastward-post" name= "email" type= "email" autofocus>
- </div>
- <divclass = "grade-group" >
- <inputclass = "form-command" placeholder= "Password" name= "pass" type= "countersign" value= "" >
- </div>
- <inputform = "btn btn-lg btn-success btn-block" blazon= "submit" value= "annals" name= "annals" >
- </fieldset>
- </form>
- <center><b>Already registered ?</b> <br></b><a href="login.php" >Login here</a></middle><!-- for centered text-->
- </div>
- </div>
- </div>
- </div>
- </div>
- </torso>
- </html>
- <?php
- include("database/db_conection.php" );
- if (isset($_POST[ 'register' ]))
- {
- $user_name=$_POST['proper noun' ];
- $user_pass=$_POST['pass' ];
- $user_email=$_POST['email' ];
- if ($user_name== '' )
- {
- echo"<script>alert('Please enter the proper noun')</script>" ;
- get out();
- }
- if ($user_pass== '' )
- {
- repeat"<script>alert('Please enter the password')</script>" ;
- exit();
- }
- if ($user_email== '' )
- {
- echo"<script>alert('Please enter the e-mail')</script>" ;
- exit();
- }
- $check_email_query="select * from users WHERE user_email='$user_email'" ;
- $run_query=mysqli_query($dbcon,$check_email_query);
- if (mysqli_num_rows($run_query)>0)
- {
- echo"<script>warning('Email $user_email is already exist in our database, Please endeavour another ane!')</script>" ;
- go out();
- }
- $insert_user="insert into users (user_name,user_pass,user_email) VALUE ('$user_name','$user_pass','$user_email')" ;
- if (mysqli_query($dbcon,$insert_user))
- {
- echo"<script>window.open('welcome.php','_self')</script>" ;
- }
- }
- ?>
Login.php
- <?php
- session_start();
- ?>
- <html>
- <caput lang="en" >
- <meta charset="UTF-8" >
- <link type="text/css" rel= "stylesheet" href= "bootstrap-3.two.0-dist\css\bootstrap.css" >
- <title>Login</title>
- </head>
- <manner>
- .login-panel {
- margin-summit: 150px;
- </style>
- <trunk>
- <divcourse = "container" >
- <divclass = "row" >
- <divform = "col-md-4 col-doctor-starting time-4" >
- <divclass = "login-panel panel console-success" >
- <divgrade = "console-heading" >
- <h3class = "panel-championship" >Sign In</h3>
- </div>
- <divclass = "console-body" >
- <form office="form" method= "post" activity= "login.php" >
- <fieldset>
- <divclass = "form-group" >
- <inputgrade = "course-control" placeholder= "E-postal service" name= "email" blazon= "email" autofocus>
- </div>
- <divcourse = "form-grouping" >
- <inputclass = "course-control" placeholder= "Password" name= "laissez passer" type= "password" value= "" >
- </div>
- <inputclass = "btn btn-lg btn-success btn-block" type= "submit" value= "login" name= "login" >
- <!-- Modify this to a push buttonor input when using this equally a form -->
- <!-- <a href="index.html" class = "btn btn-lg btn-success btn-block" >Login</a> -->
- </fieldset>
- </form>
- </div>
- </div>
- </div>
- </div>
- </div>
- </torso>
- </html>
- <?php
- include ( "database/db_conection.php" );
- if (isset( $_POST [ 'login' ]))
- {
- $user_email = $_POST [ 'email' ];
- $user_pass = $_POST [ 'pass' ];
- $check_user = "select * from users WHERE user_email='$user_email'AND user_pass='$user_pass'" ;
- $run =mysqli_query( $dbcon , $check_user );
- if (mysqli_num_rows( $run ))
- {
- echo "<script>window.open('welcome.php','_self')</script>" ;
- $_SESSION [ 'e-mail' ]= $user_email ;
- }
- else
- {
- echo "<script>alert('Electronic mail or password is incorrect!')</script>" ;
- }
- }
- ?>
Logout.php
- <?php
- session_start();
- session_destroy();
- header("Location: login.php" );
- ?>
Welcome.php
- <?php
- session_start();
- if (! $_SESSION [ 'email' ])
- {
- header("Location: login.php" );
- }
- ?>
- <html>
- <head>
- <title>
- Registration
- </title>
- </head>
- <torso>
- <h1>Welcome</h1><br>
- <?php
- echo $_SESSION [ 'email' ];
- ?>
- <h1><a href="logout.php" >Logout hither</a> </h1>
- </torso>
- </html>
Admin_login.php
- <html>
- <head lang="en" >
- <meta charset="UTF-viii" >
- <link type="text/css" rel= "stylesheet" href= "bootstrap-3.two.0-dist\css\bootstrap.css" >
- <title>Admin Login</title>
- </head>
- <style>
- .login-panel {
- margin-acme: 150px;
- </style>
- <body>
- <divclass = "container" >
- <divclass = "row" >
- <divclass = "col-doctor-four col-md-offset-4" >
- <divform = "login-panel panel panel-success" >
- <divclass = "panel-heading" >
- <h3grade = "panel-title" >Sign In</h3>
- </div>
- <divcourse = "panel-torso" >
- <form role="form" method= "postal service" activity= "admin_login.php" >
- <fieldset>
- <divcourse = "form-group" >
- <inputclass = "form-control" placeholder= "Name" proper noun= "admin_name" blazon= "text" autofocus>
- </div>
- <divclass = "form-group" >
- <inputclass = "class-control" placeholder= "Password" name= "admin_pass" type= "password" value= "" >
- </div>
- <inputclass = "btn btn-lg btn-success btn-block" type= "submit" value= "login" proper noun= "admin_login" >
- </fieldset>
- </grade>
- </div>
- </div>
- </div>
- </div>
- </div>
- </body>
- </html>
- <?php
- include("database/db_conection.php" );
- if (isset($_POST[ 'admin_login' ]))
- {
- $admin_name=$_POST['admin_name' ];
- $admin_pass=$_POST['admin_pass' ];
- $admin_query="select * from admin where admin_name='$admin_name' AND admin_pass='$admin_pass'" ;
- $run_query=mysqli_query($dbcon,$admin_query);
- if (mysqli_num_rows($run_query)>0)
- {
- echo"<script>window.open('view_users.php','_self')</script>" ;
- }
- else {echo "<script>alarm('Admin Details are incorrect..!')</script>" ;}
- }
- ?>
View_users.php
- <html>
- <head lang="en" >
- <meta charset="UTF-8" >
- <link blazon="text/css" rel= "stylesheet" href= "bootstrap-three.2.0-dist\css\bootstrap.css" > <!--css file link in bootstrap binder-->
- <title>View Users</championship>
- </head>
- <style>
- .login-panel {
- margin-elevation: 150px;
- }
- .tabular array {
- margin-acme: 50px;
- }
- </style>
- <torso>
- <divform = "tabular array-scrol" >
- <h1 align="center" >All the Users</h1>
- <divform = "tabular array-responsive" ><!-- this is used for responsive display in mobile and other devices-->
- <tableclass = "table table-bordered table-hover table-striped" style= "table-layout: fixed" >
- <thead>
- <tr>
- <th>User Id</thursday>
- <thursday>User Name</th>
- <th>User E-mail</th>
- <thursday>User Laissez passer</th>
- <th>Delete User</thursday>
- </tr>
- </thead>
- <?php
- include("database/db_conection.php" );
- $view_users_query="select * from users" ;
- $run=mysqli_query($dbcon,$view_users_query);
- while ($row=mysqli_fetch_array($run))
- {
- $user_id=$row[0];
- $user_name=$row[1];
- $user_email=$row[2];
- $user_pass=$row[3];
- ?>
- <tr>
- <!--hither showing resultsin the tabular array -->
- <td><?php echo $user_id; ?></td>
- <td><?php repeat $user_name; ?></td>
- <td><?php echo $user_email; ?></td>
- <td><?php echo $user_pass; ?></td>
- <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-->
- </tr>
- <?php } ?>
- </table>
- </div>
- </div>
- </trunk>
- </html>
Db_conection.php
- <?php
- $dbcon =mysqli_connect( "localhost" , "root" , "" );
- mysqli_select_db($dbcon , "users" );
- ?>
Delete.php
- <?php
- include ( "database/db_conection.php" );
- $delete_id = $_GET [ 'del' ];
- $delete_query = "delete from users WHERE id='$delete_id'" ;
- $run =mysqli_query( $dbcon , $delete_query );
- if ( $run )
- {
- echo "<script>window.open('view_users.php?deleted=user has been deleted','_self')</script>" ;
- }
- ?>
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
Post a Comment