title: How to login to website without a page refresh
body: <p>i am using twitter bootstrap modal window for registration form. when I click on "Register" after filling the form, it sends data to mysql and session begins. </p>
  
  <p>how to ensure that one remains at same webpage from which he has clicked "register" link.</p>
  
  <pre><code>    &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  
  &lt;link href="http://www.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" rel="stylesheet"&gt;
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script src="http://www.bootstrapcdn.com/twitter-bootstrap/2.2.1/js/bootstrap.min.js"&gt;&lt;/script&gt;
  
  
  
  
  &lt;script&gt;
     $(document).ready(function(){
       $("#ajax-contact-form").submit(function(){
        var str = $(this).serialize();
           $.ajax(
           {
           type: "POST",
           url:"register_process.php",
           data: str,
           success:function(result)
                  {
                  $("#div1").html(result);
                  }
            });
        return false;
         });
     });
  &lt;/script&gt;
  
  
  &lt;/head&gt;
  &lt;body&gt;
  &lt;a data-toggle="modal" href="#myModal" class="btn btn-primary btn-lg"&gt;SIGN UP&lt;/a&gt;
  
    &lt;div class="modal fade" id="myModal"&gt;
      &lt;div class="modal-dialog"&gt;
        &lt;div class="modal-content"&gt;
          &lt;div class="modal-header"&gt;
            &lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;&amp;times;&lt;/button&gt;
            &lt;h4 class="modal-title"&gt;Modal title&lt;/h4&gt;
          &lt;/div&gt;
          &lt;div class="modal-body"&gt;
  
  &lt;div id="contact_form"&gt;  
  &lt;form id="ajax-contact-form" name="contact" action=""&gt; 
  &lt;fieldset&gt;
      &lt;div class="field_container"&gt;First Name:&lt;/label&gt;
  &lt;input type="text" name="cust_firstname" id="firstname"  maxlength="50" style="width: 250px; height: 30px"; /&gt;
  
  
  
  &lt;div class="field_container"&gt;Last Name:&lt;/label&gt;
  &lt;input type="text" name="cust_lastname" id="lastname" maxlength="50" style="width: 250px; height: 30px"; /&gt;
  
  
  &lt;div class="sex_check" &gt;
  &lt;input type="radio" name="cust_sex" type="radio" value="M" /&gt; Male
  &lt;input type="radio" name="cust_sex" type="radio" value="F" /&gt; Female
  
  
  &lt;hr class="line_break"&gt;
  
  &lt;div class="field_container"&gt;Email:&lt;/label&gt;
  &lt;input type="text" name="cust_email" id="email"  maxlength="100" style="width: 250px; height: 30px"; /&gt;
  
  
  
  &lt;div class="field_container"&gt;Password:&lt;/label&gt;
  &lt;input type='password' name='cust_password' id='password'  maxlength="12" style="width: 250px; height: 30px"; /&gt;
  
  
  
  &lt;div class="field_container"&gt;Confirm Password:&lt;/label&gt;
  &lt;input type='password' name='cust_password2' id='confirmpassword'  maxlength="12" style="width: 250px; height: 30px"; /&gt;
  
  
  
  
  
  
  
  &lt;/div&gt;
      &lt;div class="modal-footer"&gt;
       &lt;button type="button" class="btn btn-default" data-dismiss="modal"&gt;Close&lt;/button&gt;
      &lt;INPUT class="btn btn-primary" type="submit" name="submit" value="Register" &gt;
  &lt;/fieldset&gt;  
  &lt;/form&gt;
  
  &lt;/div&gt;
      &lt;/div&gt;&lt;!-- /.modal-content --&gt;
      &lt;/div&gt;&lt;!-- /.modal-dialog --&gt;
  &lt;/div&gt;&lt;!-- /.modal --&gt;
  
  
  &lt;/div&gt; 
  
  &lt;div id="div1"&gt;
  &lt;/div&gt; 
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>register_process.php is as follows</p>
  
  <pre><code>&lt;?php
  ob_start();
  session_start();
  require_once("config.php");
  require_once("all_functions.php");
  $cust_firstname = stripslashes($_POST['cust_firstname']);
  $cust_lastname = stripslashes($_POST['cust_lastname']);
  $cust_sex = stripslashes($_POST['cust_sex']);
  $cust_email = stripslashes($_POST['cust_email']);
  $cust_password = stripslashes($_POST['cust_password']);
  $cust_password2 = stripslashes($_POST['cust_password2']);
  
  
  
  $res = mysql_query("SELECT * FROM register WHERE cust_email = '$cust_email'");
  if (mysql_num_rows($res)&gt;0)
      {
      echo 'That email is already registered';
      exit;
      }
  mysql_query("INSERT INTO register (`cust_firstname`,`cust_lastname`, `cust_sex`, `cust_email`, `cust_password`) 
  VALUES
  ('$cust_firstname', '$cust_lastname', '$cust_sex', '$cust_email', '$cust_password')");
  $_SESSION['valid_user'] = $cust_email;
      header("Location: http://tripneat.com/");
      exit;
  ?&gt;
  </code></pre>