在php中使用页眉无法正确重定向页面

在php中使用页眉无法正确重定向页面,php,redirect,Php,Redirect,我试图做的是,如果登录的成员试图移回index.php,则将其重定向到index2.php 我将这段代码放在index.php的最上面: <?php session_start(); if (isset($_SESSION['uid'])) { header ("Location :index2.php"); } else { session_unset(); session_destroy(); } 也许这是因为您在代码中的空间?试试这个 <?php se

我试图做的是,如果登录的成员试图移回index.php,则将其重定向到index2.php

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

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

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

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

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

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

调试以确保实际设置了
$\u会话['uid']
时发生了什么?您是否收到任何关于“已发送邮件头”的错误消息?是否可以设置相应的会话值?我们如何知道它被设置在某个地方,为什么以及如何设置?使用
exit(header(…)
并打开
错误报告
。它必须是:header(“Location:index2.php”);“:”必须在没有空格的位置后面。然后接受Kieran的回答:)当您调试以确保
$\u会话['uid']
实际已设置时发生了什么?您是否收到任何关于“已发送邮件头”的错误消息?是否可以设置相应的会话值?我们如何知道它被设置在某个地方,为什么以及如何设置?使用
exit(header(…)
并打开
错误报告
。它必须是:header(“Location:index2.php”);“:”必须在没有空格的位置后面。然后接受Kieran的回答:)