PHP不会重定向

时间:2015-03-27 10:04:54

标签: php redirect

当我登录/注销或注册它时,我正在一个简单的PHP论坛上工作,不会将我重定向回index.php 我的注销代码例如

<?php
if(isset($_POST['do_logout'])){
    //Create User Object

$user = new User;
    if($user->logout()){
        redirect('index.php','You are now logged out','success');
} 
} else {
    redirect('index.php');
}

和我的重定向代码

<?php
function redirect($page = FALSE, $message = NULL, $message_type = NULL) {
    if (is_string ($page)) {
        $location = $page;
    } else {
        $location = $_SERVER ['index.php'];
    }
    if($message != NULL){
        $_SESSION['message'] = $message;
    }
    if($message_type != NULL){
        $_SESSION['message_type'] = $message_type;
    }
header('Location: '.$location);
    exit(); 
}

定义脚本位于注销脚本

之前的php文件中

1 个答案:

答案 0 :(得分:0)

<?php
function redirect($page = FALSE, $message = NULL, $message_type = NULL) {

    $location = (is_string($page)) ? $page : 'index.php';

    if($message != NULL){
        $_SESSION['message'] = $message;
    }

    if($message_type != NULL){
        $_SESSION['message_type'] = $message_type;
    }

    header('Location: '. $location); exit(); 
}