首页 > 解决方案 > 虽然我使用 header('Location:test.php') 我必须重新加载页面

问题描述

$('#logOut').click(function()
    {
        <?php
            //session_start(); comment this because this is called top of the page.
            unset($_SESSION['email']);
            unset($_SESSION['password']);
            header('Location: test.php');
        ?>
    });

这是里面的newnavbar.phptest.php页面加载此页面。

$(function(){
  $("#nav-placeholder").load("newnavbar.php");
});

我也使用header('Refresh:0, url= test.php');,但在这两种情况下,我都必须手动重新加载页面。

编辑 1
登录时发生相同的情况。登录后我必须重新加载页面,然后显示用户头像代替登录按钮。如果我重新加载两次,那么用户就退出了。

我也用

$('#signInSubmit').click(function() 
    {
        $('#signIn').modal('toggle');
        //alert("signup completed");
        var email=document.getElementById('signInEmail').value;
        var password = document.getElementById('signInPassword').value;
        $.ajax({
            url: 'signIn.php',
            type: 'POST',
            data: {
                email: email,
                password: password
            },
            success: function(data)
            {
                alert(data);
                <?php header('Location: test.php'); ?>
            },
            error: function(data)
            {
                console.log(data);
            }            
        });
    });

但是,test.php页面未显示成功。

标签: phpsession

解决方案


推荐阅读