Solved

Login Submit - No Page Refresh

Posted on 2013-11-13
1
484 Views
Last Modified: 2013-11-13
My current login page if the login is incorrect the page refreshes and says that the username/pass is incorrect.  I want to do this so that it doesn't refresh the page.

<?php
  define("_VALID_PHP", true);
  require_once("init.php");
  
  if ($user->logged_in)
      redirect_to("/client/dashboard");
	  
	  
  if (isset($_POST['doLogin']))
      : $result = $user->login($_POST['username'], $_POST['password']);
  
  /* Login Successful */
  if ($result)
      : redirect_to("/client/dashboard");
  endif;
  endif;
?>
<?php include("header.php");?>
<div id="msgholder-alt"><?php print $core->showMsg;?></div>
    <div class="box">
      <form action="" method="post" id="login_form" name="login_form">
        <table width="100%" border="0" cellpadding="3" cellspacing="0" class="display">
          <tr>
            <th width="200"><strong>Username:</strong></th>
            <td><input name="username" type="text" size="45" maxlength="20" class="inputbox" /></td>
          </tr>
          <tr>
            <th><strong>Password:</strong></th>
            <td><input name="password" type="password" size="45" maxlength="20" class="inputbox" /></td>
          </tr>
          <tr>
            <td><input name="submit" value="Login Now" type="submit" class="button"/></td>
          </tr>
        </table>
        <input name="doLogin" type="hidden" value="1" />
      </form>
    </div>

Open in new window

0
Comment
Question by:N R
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39645723
Put this in the head section of your page  :

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    $("#logindropdown img").click(function() {
          var u = $("#logindropdown input[name='username']").val();
          var p = $("#logindropdown input[name='password']").val();
          $.post("simple_login_to_attack.php", {username:u, password:p}, function(result) {
              if(result=="ok") location.href = "/client/dashboard";
              else alert("bad login/password");
          });
    })
})
</script>

Open in new window


with simple_login_to_attack.php:
<?php
  define("_VALID_PHP", true);
  require_once("init.php");
  if ($user->logged_in) die("ok");
  $result = $user->login($_POST['username'], $_POST['password']);
  if ($result) die("ok");
  die("fail");
?>

Open in new window

0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now