【问题标题】:Jquery mobile + Php authentication systemjquery mobile+php认证系统
【发布时间】:2012-06-30 20:59:50
【问题描述】:

我正在用移动 jquery 和 php 编写一个身份验证系统。 html代码如下:

    <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</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 函数来启动和销毁 php 会话,并根据 ajax 响应使用 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();
        }
    })
}

我尝试关闭会话,然后在每个页面上使用安全功能来验证会话。但是一旦销毁会话,我就可以返回一个页面而不是跳过对话。

有什么想法吗?

【问题讨论】:

    标签: jquery session mobile


    【解决方案1】:

    我认为您的问题是 jQueryMobile 在 DOM 中保留了以前访问过的页面的缓存。您应该尝试删除所有页面(或至少是第一页),以便当用户重新访问它时,jQueryMobile 将重新获取其内容并触发您的会话代码。

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

    【讨论】:

    • $.mobile.changePage 不能用于成功的 ajax 函数,如果 html 文件是多页的,我如何在页面中使用 remove() 方法,第一页#dialogo,我应该t 删除,因为是第一页。现在,我不知道为什么按下后退按钮时会使用 URL index.php 执行 get ajax(这是运行 jquery get 并且不知道为什么)。有了这一切,功能是正确的
    【解决方案2】:

    我做的应用退出按钮如下:

    注销.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 不会重定向到初始对话。 有什么想法吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-02
      • 2020-05-13
      • 1970-01-01
      • 1970-01-01
      • 2011-04-16
      • 2011-10-25
      • 1970-01-01
      相关资源
      最近更新 更多