如何在PHP中重定向?

时间:2014-09-25 06:53:11

标签: php redirect

搜索了过去一小时的网页,但没有一个解决方案适合我。

我的signUp或登录功能都不会重定向。

在我设置标题之前,我没有做任何回音。

我目前的代码:

<?php
    require_once($_SERVER["DOCUMENT_ROOT"].'/Model/User/UserDto.php');
    require_once($_SERVER["DOCUMENT_ROOT"].'/Model/FacadeFactory.php');

    $action = $_GET['action'];
    $action();

    function signUp() {
        $email = $_POST['email'];
        $password = $_POST['password'];

        $userDto = new UserDto($email, $password);
        FacadeFactory::getDomainFacade()->signUp($userDto);
        FacadeFactory::getDomainFacade()->login($userDto);


        $location = sprintf("Location: %s%s",$_SERVER["HTTP_HOST"], "/View/Dashboard");
        header($location);
        exit();
    }

    function login() {
        $email = $_POST['email'];
        $password = $_POST['password'];

        $userDto = new UserDto($email, $password);
        FacadeFactory::getDomainFacade()->login($userDto);

        $location = sprintf("Location: %s%s",$_SERVER["HTTP_HOST"], "/View/Dashboard");
        ob_start();
        header($location);
        exit();
    }
?>

1 个答案:

答案 0 :(得分:1)

$_SERVER["HTTP_HOST"]中不需要

header('Location: ')。您可以将其删除并使用header("Location: /View/Dashboard");