Php 会话过期时如何移动到登录页面

Php 会话过期时如何移动到登录页面,php,ajax,Php,Ajax,当会话过期时,我遇到了问题,我没有移动到登录页面,但我遇到了错误,因为无法连接到serer,正如我的ajax代码所示 function driver() { $this = $(this); $.ajax( { url: 'view/driver/driver.php', datatype: 'html',

当会话过期时,我遇到了问题,我没有移动到登录页面,但我遇到了错误,因为无法连接到serer,正如我的ajax代码所示

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);
php url文件如下所示:

<div id="content" class="span10">
            <!-- content starts -->
<div class="row-fluid sortable">
<div class="box span12">

$userid=$_SESSION['USERID'];
if(empty($userid)){
header('location:localhost/test/login.php');
}
                    <div class="box-header well" data-original-title>
                        <h2><i class="icon-user"></i> All Driver</h2>

                    </div>
                    <div class="box-content">
                        <table class="table table-striped table-bordered bootstrap-datatable datatable">
                          <thead>
                              <tr>
                                                                  <th>Driver user ID</th>
                                  <th>FName</th>
                                                                  <th>LName</th>
                                  <th>Phone NO.</th>
                                                                  <th>Is Verified</th>
                                  <th>Action</th>
                              </tr>
                          </thead>
                          <tbody>


                                                      <?php

                                                      include '../../config.php';
                                                      $query = "select * from driver_user";
                                                      $result = mysql_query($query);
                                                      while ($row = mysql_fetch_array($result))
                                                      {

                                                      ?>


                            <tr>
                                                            <td style="width: 8%;"><?php echo $row['driver_user_id']; ?></td>
                                                                <td style="width: 10%;"><?php echo $row['first_name']; ?></td>
                                                                <td style="width: 10%;"><?php echo stripslashes($row['last_name']); ?></td>
                                <td style="width: 8%;"><?php echo $row['phone_no']; ?></td>
                                <td style="width: 5%;<?php if($row['isverified'] == 'Verified'){ echo 'color:green;';} 
                                                                                 if($row['isverified'] == 'Approval'){ echo 'color:blue;';} 
                                                                                 if($row['isverified'] == 'Not Verified'){ echo 'color:red;';}
                                                                                 ?>"> <?php echo $row['isverified']; ?></td>
                                                         <td style="width:15%;" class="center" itemid="<?php echo $row['driver_user_id']; ?>">
                                    <a class="btn btn-success driver_view" href="#">
                                        <i class="icon-zoom-in icon-white driver_view"></i>
                                        View/ Edit
                                    </a>
<!--                                    <a class="btn btn-info driver_edit_form" href="#">
                                        <i class="icon-edit icon-white"></i>
                                        Edit
                                    </a>-->
                                    <a class="btn btn-danger delete_driver" href="#">
                                        <i class="icon-trash icon-white"></i>
                                        Delete
                                    </a>


                                </td>


                                                      <?php } ?>

                                                </tr>

                                      </tbody>
                      </table>
                    </div>
                </div><!--/span-->

</div><!--/row-->



<div class="row-fluid sortable">



                     </div><!--/row-->

                    <!-- content ends -->
            </div><!--/#content.span10-->
若会话过期,我不会移动到登录页面,但它显示错误无法连接到php文件中的数据库。首先,我检查会话

plz帮助我在调用ajax代码之前检查会话


感谢并问候

您将数据发送到浏览器后无法使用标题,您已开始将数据发送到浏览器:

<div id="content" class="span10">
使用location.href javascript或

缓冲区

<? ob_start();?>
    <div id="content" class="span10">
     .....
    if(empty($userid))
   {
        header('location:localhost/test/login.php');
        exit;
   }
    ......
<? ob_flush(); ?>