Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.59 KB | None | 0 0
  1. <head>
  2. <script src="jquery.js" type="text/javascript" language="javascript"></script>
  3.  
  4. <script language="javascript">         
  5. $(document).ready(function()
  6. {
  7.     $("#login_form").submit(function()
  8.     {
  9.         //remove all the class add the messagebox classes and start fading
  10.         $("#msgbox").removeClass().addClass('messagebox').text('Validating....').fadeIn(1000);
  11.         //check the email exists or not from ajax
  12.         $.post("ajax_login.php",{ email:$('#email').val(),password:$('#password').val(),rand:Math.random() } ,function(data)
  13.         {
  14.           if(data=='yes') //if correct login detail
  15.           {
  16.             $("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
  17.             {
  18.               //add message and change the class of the box and start fading
  19.               $(this).html('Logging in.....').addClass('messageboxok').fadeTo(900,1,
  20.               function()
  21.               {
  22.                  //redirect to secure page
  23.                  document.location='adminhome.php';
  24.               });
  25.              
  26.             });
  27.           }
  28.           else
  29.           {
  30.             $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
  31.             {
  32.               //add message and change the class of the box and start fading
  33.               $(this).html('Try again...').addClass('messageboxerror').fadeTo(900,1);
  34.             });    
  35.           }
  36.                
  37.         });
  38.         return false; //not to post the  form physically
  39.     });
  40.     //now call the ajax also focus move from
  41.     $("#password").blur(function()
  42.     {
  43.         $("#login_form").trigger('submit');
  44.     });
  45. });
  46.  
  47. </head>
  48.  
  49. <body>
  50. <form method="POST" action="" id="login_form">
  51. <div align="center">
  52. <div >
  53.    E-mail : <input name="email" type="text" id="email" value="" maxlength="30" />
  54.  
  55. </div>
  56. <div style="margin-top:5px" >
  57.    Password : <input name="password" type="password" id="password" value="" maxlength="30" />
  58.    
  59. </div>
  60. <div class="buttondiv">
  61.     <input name="Submit" type="submit" id="submit" value="Login" style="margin-left:-10px; height:27px"  /> <span id="msgbox" style="display:none"></span>
  62.    
  63. </div>
  64.  
  65. </div>
  66. </form>    
  67. </body>
  68.  
  69.  
  70.  
  71.  
  72. ===============
  73. ajax_login.php
  74. ===============
  75.  
  76. <?php
  77.  
  78. require("session.php");
  79. require("db.php");
  80.  
  81.  
  82. //get the posted values
  83. $email=$_POST['email'];
  84. $password=$_POST['password'];
  85.  
  86. //now validating the username and password
  87. $sql="SELECT * FROM admin WHERE email='".$email."'";
  88. $result=mysql_query($sql);
  89. $row=mysql_fetch_array($result);
  90.  
  91. //if username exists
  92. if(mysql_num_rows($result)>0)
  93. {
  94.     //compare the password
  95.     if(strcmp($row['password'],$password)==0)
  96.     {
  97.         echo "yes";
  98.         //now set the session from here if needed
  99.         $_SESSION['email']=$email;
  100.     }
  101.     else
  102.         echo "no";
  103. }
  104. else
  105.     echo "no"; //Invalid Login
  106.  
  107.  
  108. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement