title: how to move to login page if session is expired
body: <p>i got i problem when the session is expire i does not move to login page but i got error as can not connect to serer as my ajax code looks like</p>
  
  <pre><code>function driver()
      {
  
           $this = $(this);
           $.ajax(
                         {
  
                       url: 'view/driver/driver.php',
  
                           datatype: 'html',
                           async:true,
                           success: function(data){
                   $box = $('#content');
                           $box.after(data);
                           $box.remove();
  
                           }
                       });
  }
  $(document).on('click','#driver',$(this),driver);
  </code></pre>
  
  <p>and the php url file as </p>
  
  <pre><code>&lt;div id="content" class="span10"&gt;
              &lt;!-- content starts --&gt;
  &lt;div class="row-fluid sortable"&gt;
  &lt;div class="box span12"&gt;
  
  $userid=$_SESSION['USERID'];
  if(empty($userid)){
  header('location:localhost/test/login.php');
  }
                      &lt;div class="box-header well" data-original-title&gt;
                          &lt;h2&gt;&lt;i class="icon-user"&gt;&lt;/i&gt; All Driver&lt;/h2&gt;
  
                      &lt;/div&gt;
                      &lt;div class="box-content"&gt;
                          &lt;table class="table table-striped table-bordered bootstrap-datatable datatable"&gt;
                            &lt;thead&gt;
                                &lt;tr&gt;
                                                                    &lt;th&gt;Driver user ID&lt;/th&gt;
                                    &lt;th&gt;FName&lt;/th&gt;
                                                                    &lt;th&gt;LName&lt;/th&gt;
                                    &lt;th&gt;Phone NO.&lt;/th&gt;
                                                                    &lt;th&gt;Is Verified&lt;/th&gt;
                                    &lt;th&gt;Action&lt;/th&gt;
                                &lt;/tr&gt;
                            &lt;/thead&gt;
                            &lt;tbody&gt;
  
  
                                                        &lt;?php
  
                                                        include '../../config.php';
                                                        $query = "select * from driver_user";
                                                        $result = mysql_query($query);
                                                        while ($row = mysql_fetch_array($result))
                                                        {
  
                                                        ?&gt;
  
  
                              &lt;tr&gt;
                                                              &lt;td style="width: 8%;"&gt;&lt;?php echo $row['driver_user_id']; ?&gt;&lt;/td&gt;
                                                                  &lt;td style="width: 10%;"&gt;&lt;?php echo $row['first_name']; ?&gt;&lt;/td&gt;
                                                                  &lt;td style="width: 10%;"&gt;&lt;?php echo stripslashes($row['last_name']); ?&gt;&lt;/td&gt;
                                  &lt;td style="width: 8%;"&gt;&lt;?php echo $row['phone_no']; ?&gt;&lt;/td&gt;
                                  &lt;td style="width: 5%;&lt;?php if($row['isverified'] == 'Verified'){ echo 'color:green;';} 
                                                                                   if($row['isverified'] == 'Approval'){ echo 'color:blue;';} 
                                                                                   if($row['isverified'] == 'Not Verified'){ echo 'color:red;';}
                                                                                   ?&gt;"&gt; &lt;?php echo $row['isverified']; ?&gt;&lt;/td&gt;
                                                           &lt;td style="width:15%;" class="center" itemid="&lt;?php echo $row['driver_user_id']; ?&gt;"&gt;
                                      &lt;a class="btn btn-success driver_view" href="#"&gt;
                                          &lt;i class="icon-zoom-in icon-white driver_view"&gt;&lt;/i&gt;
                                          View/ Edit
                                      &lt;/a&gt;
  &lt;!--                                    &lt;a class="btn btn-info driver_edit_form" href="#"&gt;
                                          &lt;i class="icon-edit icon-white"&gt;&lt;/i&gt;
                                          Edit
                                      &lt;/a&gt;--&gt;
                                      &lt;a class="btn btn-danger delete_driver" href="#"&gt;
                                          &lt;i class="icon-trash icon-white"&gt;&lt;/i&gt;
                                          Delete
                                      &lt;/a&gt;
  
  
                                  &lt;/td&gt;
  
  
                                                        &lt;?php } ?&gt;
  
                                                  &lt;/tr&gt;
  
                                        &lt;/tbody&gt;
                        &lt;/table&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;&lt;!--/span--&gt;
  
  &lt;/div&gt;&lt;!--/row--&gt;
  
  
  
  &lt;div class="row-fluid sortable"&gt;
  
  
  
                       &lt;/div&gt;&lt;!--/row--&gt;
  
                      &lt;!-- content ends --&gt;
              &lt;/div&gt;&lt;!--/#content.span10--&gt;
  </code></pre>
  
  <p>I does not move to login page if session is expire yet it show error can't connect to database in php file first of all i check session </p>
  
  <p>plz help me how to check session before any call of ajax code.</p>
  
  <p>thanks and regards</p>