Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <head>
- <script src="jquery.js" type="text/javascript" language="javascript"></script>
- <script language="javascript">
- $(document).ready(function()
- {
- $("#login_form").submit(function()
- {
- //remove all the class add the messagebox classes and start fading
- $("#msgbox").removeClass().addClass('messagebox').text('Validating....').fadeIn(1000);
- //check the email exists or not from ajax
- $.post("ajax_login.php",{ email:$('#email').val(),password:$('#password').val(),rand:Math.random() } ,function(data)
- {
- if(data=='yes') //if correct login detail
- {
- $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
- {
- //add message and change the class of the box and start fading
- $(this).html('Logging in.....').addClass('messageboxok').fadeTo(900,1,
- function()
- {
- //redirect to secure page
- document.location='adminhome.php';
- });
- });
- }
- else
- {
- $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
- {
- //add message and change the class of the box and start fading
- $(this).html('Try again...').addClass('messageboxerror').fadeTo(900,1);
- });
- }
- });
- return false; //not to post the form physically
- });
- //now call the ajax also focus move from
- $("#password").blur(function()
- {
- $("#login_form").trigger('submit');
- });
- });
- </head>
- <body>
- <form method="POST" action="" id="login_form">
- <div align="center">
- <div >
- E-mail : <input name="email" type="text" id="email" value="" maxlength="30" />
- </div>
- <div style="margin-top:5px" >
- Password : <input name="password" type="password" id="password" value="" maxlength="30" />
- </div>
- <div class="buttondiv">
- <input name="Submit" type="submit" id="submit" value="Login" style="margin-left:-10px; height:27px" /> <span id="msgbox" style="display:none"></span>
- </div>
- </div>
- </form>
- </body>
- ===============
- ajax_login.php
- ===============
- <?php
- require("session.php");
- require("db.php");
- //get the posted values
- $email=$_POST['email'];
- $password=$_POST['password'];
- //now validating the username and password
- $sql="SELECT * FROM admin WHERE email='".$email."'";
- $result=mysql_query($sql);
- $row=mysql_fetch_array($result);
- //if username exists
- if(mysql_num_rows($result)>0)
- {
- //compare the password
- if(strcmp($row['password'],$password)==0)
- {
- echo "yes";
- //now set the session from here if needed
- $_SESSION['email']=$email;
- }
- else
- echo "no";
- }
- else
- echo "no"; //Invalid Login
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement