2012-06-29 41 views
0

我正在寫一個認證系統與移動jQuery和PHP。 html代碼如下:Jquery手機+ PHP認證系統

<div data-role = "page" id ="dialogo"> 
     <a href = "#identificacion" id = "formdialog" data-rel="dialog"> </a> 
    </div> 

    <div data-role = "page" id = "identificacion"> 
     <div id ="main"> 
      <div id ="caplogin"> 
       <img src = "images/vives_logo.png"/> 
       <p> Acceso Promoción Vives </p> 
       <div style ="clear:both;"></div> 
      </div> 
      <div style ="clear:both;"></div> 
      <div id ="formlogin"> 
      <form name ="formautentificacion" id ="formautentificacion" method = "post" action = "" data-ajax="false"> 
       <table> 
        <tr> <td> Login </td> <td> <input type ="text" name ="user" id ="user" size="30"/></td> </tr> 
        <tr> <td> Password </td><td><input type ="password" name ="pass" id="pass" size="30"/></td></tr> 
        <tr> <td colspan = "2" align ="right"> <input type = "submit" id = "sbmt_aut" name = "sbmt_aut" value = "ENTRAR"/></td> 
       </table> 
      </form> 
      </div> 
     </div> 
    </div> 

    <div data-role = "page" id = "pageclients"> 

     <div id = "headerpageclient"> 
      <a href="index.php" class ="logout" data-role="button" data-icon="delete">SALIR</a> 
     </div> 
     <div id = "clientes"> 

     </div> 
    </div> 

    <div data-role = "page" id = "pagepuntosventa"> 
     <div id = "headerpagepuntoventa"> 

     </div> 
    </div> 

我有兩個AJAX功能與Ajax響應,根據它來啓動和破壞PHP會話,並使用changepage,登錄的功能是正確的,註銷,但Safari瀏覽器後退按鈕不工作,並落在最後一頁。

$(document).delegate("#dialogo", "pageinit", function() { 
    $("#formdialog").click(); 
}) 


    $(document).delegate("#identificacion", "pageinit", function() { 


    $("#formautentificacion").submit(function(e){ 
     e.preventDefault(); 
     //e.stopImmediatePropagation(); 

     $.ajax({ 
      type: 'POST', 
      url: 'ax/login.php', 
      data:$(this).serialize(), 
      cache: false, 
      success: function(data) 
      { 
       if(data == 1) 
       { 
        //$.mobile.changePage("promocion.php", {transition: "flip"}); 
        //window.location = "index.php"; 
        $.mobile.changePage("#pageclients", {transition: "flip"}); 
       } 
       else 
       { 
        if (data == 2) 
         alert("Usuario bloqueado, 3 intentos fallidos"); 
        else 
         alert("Error en la identificación"); 
       } 

       $("#user").val(""); 
       $("#pass").val(""); 
      } 
     }) 
    }) 

    $(".logout").click(function(e){ 
     //e.preventDefault(); 
     logout(); 
    }) 
}) 

$(document).delegate("#pageclients", "pageinit", function() { 
    seguridad(); 
}) 

功能SEGURIDAD()進行檢查的會話是:

session_start(); 

include("../class/aut.php"); 
$aut = new aut(); 

$res = 0; 

if (!empty($_SESSION["usuario"]) && !empty($_SESSION["token"])) 
{ 
    $_SESSION["usuario"] = mysql_real_escape_string($_SESSION["usuario"]); 
    $_SESSION["token"] = mysql_real_escape_string($_SESSION["token"]); 

    if ($aut->checktoken($_SESSION["usuario"],$_SESSION["token"])) 
    { 
     $_SESSION["token"] = md5(rand().$_SESSION["usuario"]); 
     $aut->updateToken($_SESSION["usuario"], $_SESSION["token"]); 
     $res = 1; 
    } 
    else 
    { 
     session_destroy(); 
     session_unset(); 
     $res = 0; 
     //header("Location: index.php"); 
     //exit; 
    } 
} 
else 
{ 
    session_destroy(); 
    session_unset(); 
    $res = 0; 
    //header("Location: index.php"); 
    //exit; 
} 

echo $res; 
?> 

和功能註銷:

function logout() 
{ 
    $.ajax({ 
     type: 'GET', 
     url: 'ax/logout.php', 
     cache:false, 
     //async: false, 
     success: function(data) 
     { 
      $("#formdialog").click(); 
     } 
    }) 
} 

我嘗試關閉會話,然後用安全每一頁上函數來驗證會話。但是一旦摧毀了會議,我可以回到一個頁面而不是跳過對話。

任何想法?

回答

0

我認爲你的問題是,jQueryMobile保存DOM中以前訪問過的頁面的緩存。您應該嘗試刪除所有頁面(或至少第一頁),以便當用戶重新訪問它時,jQueryMobile將重新獲取其內容並觸發您的會話代碼。

$('#somepage').remove(); 
+0

$ .mobile.changePage無法成功成功ajax函數,如果html文件是多頁,我如何使用remove()方法的頁面,第一頁#dialogo,我不應該刪除,因爲是第一頁。 現在,我不知道爲什麼當按下後退按鈕執行與URL index.php(這是運行jquery get並不知道爲什麼)獲取ajax。 所有這一切,功能是正確的 – vllopico

0

按鈕,退出我所做的應用程序如下:

logout.php

<?php 
session_start(); 
session_unset(); 
session_destroy(); 
?> 

的js

function logout() 
{ 
    $.ajax({ 
     type: 'GET', 
     url: 'ax/logout.php', 
     cache:false, 
     //async: false, 
     success: function(data) 
     { 
      console.log("LOGOUT"); 
      //$.mobile.changePage("#dialogo"); 
     } 

    }) 
    $.mobile.changePage("http://10.0.74.199/representantes"); 
} 

並註銷

鏈接
<a href="index.php" class ="logout ui-btn-right" data-role="button" data-icon="delete" data-theme="a">Salir</a> 

和HTML的最前一頁頁:

<div data-role = "page" id ="dialogo"> 
      <a href = "#identificacion" id = "formdialog" data-rel="dialog"> </a> 
     </div> 

     <div data-role = "page" id = "identificacion" data-overlay-theme="f"> 
      <div id ="main"> 
       <div id ="caplogin"> 
        <img src = "http://10.0.74.199/representantes/images/vives_logo.png"/> 
        <p> Acceso Promoción Vives </p> 
        <div style ="clear:both;"></div> 
       </div> 
       <div style ="clear:both;"></div> 
       <div id ="formlogin"> 
       <form name ="formautentificacion" id ="formautentificacion" method = "post" action = "" data-ajax="false"> 
        <table> 
         <tr> <td> Login </td> <td> <input type ="text" name ="user" id ="user" size="30"/></td> </tr> 
         <tr> <td> Password </td><td><input type ="password" name ="pass" id="pass" size="30"/></td></tr> 
         <tr> <td colspan = "2" align ="right"> <input type = "submit" id = "sbmt_aut" name = "sbmt_aut" value = "ENTRAR"/></td> 
        </table> 
       </form> 
       </div> 
      </div> 
     </div> 

當第pageinit,強制點擊

$(document).delegate("#dialogo", "pageinit", function() { 
    $("#formdialog").click(); 
}) 

有了這個,如果你關閉應用程序,但是當我點擊後退按鈕歷史上的這一失敗, index.php不會重定向到初始dialeg。 任何想法?