Search This Blog

07 March 2018

PHP Using Login Page

PHP USING LOGIN PAGE

1 1)   Signup the User Profile

   2)   Next to Login the your username and password put it Textbox 



<html>
<head></head>
// if you want any addition style sheet or online link add this 
<title> login page using php and sign up page </title>
<style>
.col1{
          position:relative;
          width:100%;
          height:100%;
       background-color:white;
      color: black;
}

.col2{
position: absolute;
    width: 40%;
    height: 55%;
    background-color: #F2F2F2;
    margin-left: 28%;
    margin-top: 8%; 
         
}
.inpt{
  padding: 12px;
   width:55%;
    border-radius: 4px;
    margin-left: 24%;
    border: 1px solid gray;
    padding-top:1px;
    marigin-top:1px;
   margin-left:1px;
margin-right:2px;
         
}
.btn{
    margin-left: 40%;
    border-radius: 4px;
    border: none;
    width: 16%;
    height: 10%;
    color:white;
    background-color: #6C7DD0;
}
</style>
<body> // body of the div
<div class="col1">
          <div class="col2">
          <br>
          <br>
          <br>  // form element starting this block
                   <form method="post" action="" enctype="multipart/form-data">
         <input type="text"  name=" uname " placeholder=" Enter Your username " class=" inpt "><br>
               <br>
                    <input type=" password "  name=" pwd " id=" pwd " placeholder=" Enter Your Password " class=" inpt "><br>
               <br>
                    <input type=" submit " onclick=' check(); ' value="login" name=" sub " class=" btn ">
                   </form>
          </div>
</div>
</body>
</html>
<?php
session_start(); // session starting 
// connect to the database
$con=mysqli_connect("localhost","root","","test"); 
// check the submit button is clicked or not 
if(isset($_POST['sub'])){
// get the post values using $_POST[''] method
$uname=$_POST['uname'];
$pwd=$_POST['pwd'];
$_SESSION['uname']=$uname;
$_SESSION['time']=time()+(30*60);
$sql=" select * from login where uname='$uname' and pwd='$pwd' ";
$res=$con->query($sql);
//counr the number of rows in the table
$cnt=mysqli_num_rows($res);
// check if  the record is no or yes
if($cnt==1){
echo "<script>alert('login sucessfully');window.location.href='logsuccess.php';</script>";
}else{
echo " <script> alert (' Your username or Password is wrong '); </script>";    
}
}
else{
echo " the user is not click the the submit button ";

}
?>

After Login:

<?php

// session start in this block
session_start();
// connect to the database 
$con=mysqli_connect("localhost","root","","test");
// print the logged user and get the session variable
echo "WELCOME MR".$_SESSION['uname']."<br>";
// the user is inactivity or something else automatically logout the session  
$now=time();
if($now > $_SESSION['time']){
          echo "<script> window.location.href=' loginpage.php '; </script> ";
          session_destroy();
}else{
   echo " user is active or working fine " ;
          //your statements;
}

Output:








No comments:

Post a Comment

Jquery or Javascript Start Exam Time

 <script> function startTimer() {      var date = "<?php echo $date ?>"; // dynamic date      var time = "<?...