使用data-ajax在重置会话后调用新页面


Using data-ajax to call new page after reset session

我有一个多页和工作在手机上,我使用PHP会话保持一致性,我在顶部添加了一个注销按钮,会话应该被清除并重新加载登录页面。下面是页面内容,点击注销按钮后登录页面被重定向,但会话id似乎没有被清除。我已经用data-ajax=false加载了注销

HTML

<body class="ui-mobile-viewport ui-overlay-a">
    <section id="home" data-role="page">
        <header data-role="header">
            <h1>Summary</h1>
        </header>
        <article data-role="content" class="ui-content" role="main">
            <button href="#signin_section">Sign-in</button><br>
        </article> <!-- article content -->
    </section> <!-- section home -->
    <section id="signin_section" data-role="page">
        <header data-role="header">
            <h1>Summary</h1>
                <a href="/admin" data-ajax="false" class="ui-btn-right ui-icon-power ui-btn ui-btn-icon-notext">Logout</a>
        </header>
        <article data-role="content" class="ui-content" role="main">
                <div id="signin">
                    <form action="checklogin.php" name="form" id="form" method="post">
                        ... (content omitted) ...
                    </form>
                </div>
        </article> 
    </section> 
</body>

Logout的PHP脚本

<?php
    session_start();
    unset($_SESSION['login']);
    session_destroy();
    header("Location: http://jetsodev.aimedia.hk/admincheck");
?>

PHP登录脚本

<?php
    session_start(); 
        if (isset($_SESSION['login'])) {
        ....
    }
?>

您应该使用session_unset而不是session_destroy,因为后者"不会取消设置与会话相关的任何全局变量,也不会取消设置会话cookie"