Explaination:
In this tutorial i have explained the way of login concept.In this tutorial i has using PHP to check the conditions whether the username
is Correct or Wrong.If the Username is Correct it further procedd the Step orelse it shows the error by using <?php if(isset($error)){ echo $error;}?>
this PHP Condition.Because of using isset condition suppose if your not upload the files it seems notice error so we avoid this problem we'll use
isset PHP condition.
index.php:
In this tutorial i have explained the way of login concept.In this tutorial i has using PHP to check the conditions whether the username
is Correct or Wrong.If the Username is Correct it further procedd the Step orelse it shows the error by using <?php if(isset($error)){ echo $error;}?>
this PHP Condition.Because of using isset condition suppose if your not upload the files it seems notice error so we avoid this problem we'll use
isset PHP condition.
index.php:
<html> <head> <style> #loginform{background-color;#000;color:#FFF;margin:0px auto;} </style> </head> <form id="loginform" method="post" action="select.php"> <p class="animate4 "><input type="text" id="username" name="username" placeholder="Username" autocomplete="off" required /></p> <p class="animate5 "><input type="password" id="password" name="password" placeholder="Password" autocomplete="off" required /></p> <p class="animate6 "><input type="submit" class="btn-block" name="submit" value="Submit"></p> <p class="warningmsg" style="color:#F00;"><?php if(isset($error)){ echo $error;}?></p> </form> </html>
In his first conditon is to connect the databse anf if isset condition is used for to check is the if the value is set and it is not null. If the condition is not null it enters into if condition otherwise it shows mysql_error.Then we have to write to do one more steps to store the username in one variable that variable SESSION.Why we use session means we can use it any files for our future use. Then we have to select the query wherether we POST that Value and DB field value is equal r not equal(i.e..)username and Password values.Before the sessions we have to start session ie,session_start.
select.php:
<?php include("db.php"); session_start(); if(isset($_POST['submit'])) { if(!$_POST['username'] || !$_POST['password'] ) { $error = "Please enter all details !!"; } else { $username=$_POST['username']; $password=$_POST['password']; $sql="select * from adminlogin where username='$username' and password='$password'"; $select=mysql_query($sql); $row=mysql_fetch_array($select); $_SESSION['login']=$row['username']; if ($row['username']) { echo '<script type="text/javascript">alert("Successfully Login");</script>'; header("location:dashboard.php"); } else { $error="<span class='error-box'>Your Login Username or Password is invalid </span>"; }} } ?>
$_SESSION['login'] before we store the username in one session variable means we can declare here and check here the condition if the session is not equal to that session value it redirect to index.php page else it proceed further login page successfully
session.php:
<?php include('db.php'); session_start(); $user_check=$_SESSION['login']; $ses_sql=mysql_query("select username from adminlogin where username='$user_check' "); $row=mysql_fetch_array($ses_sql); $login_session=$row['username']; if(!isset($login_session)) { header("Location: index.php"); } ?>
I hope this Tutorial is very Usefull for the beginners who is fresher to core PHP this tutorial is very usefull for to learn
the Login COncepts and how the session is to be work on in that.
No comments:
Post a Comment