页面没有正确重定向使用头在php


page is not redirecting properly using header in php

我要做的是重定向登录成员到index2.php,如果他试图移动回index.php

我把这段代码放在index.php的最上面:

<?php
session_start();
if (isset($_SESSION['uid'])) {
    header ("Location :index2.php");
} else {
    session_unset();
    session_destroy();
}

这段代码的预期行为是将成员重定向到index2.php,但它没有,并且index.php正在运行,我该如何解决这个问题?

也许这是因为您的代码中的空间?试试这个…

<?php
session_start();
if (isset($_SESSION['uid'])) {
    header ("Location: index2.php");
} else {
    session_unset();
    session_destroy();
}

注意location:

的变化