-4

我设置了一个简单的注册表单,将详细信息发送到我的函数以将数据放入数据库中,我希望页面重定向到成功页面......

这在我的本地服务器上非常有效,但是当我将它上传到我的实时服务器时,它只是没有重定向

不起作用的重定向在第 65 行 :) 它只是重定向到 register.php?success

任何帮助将不胜感激。我见过一些人有同样的问题,但他们的解决方案对我不起作用:(

所有其他标题位置都有效。只是这个不会:@

    <?php
    include 'core/init.php';
    //check if logged in
    logged_in_redirect();
    include 'includes/overall/header.php'; 

if (empty($_POST) === FALSE) {
    $required_fields = array('username', 'password', 'password_again', 'first_name', 'last_name', 'email');
    foreach ($_POST as $key => $value) {
        if (empty($value) && in_array($key, $required_fields) === true) {
            $errors[] = 'You appear to have missed something out, all fields are required.';
            break 1;

        }
    }

    if (empty($errors) === true) {
        if (user_exists($_POST['username']) === true ) {
            $errors[] = 'Sorry, the username \'' . $_POST['username'] . '\' is already taken.';
        }
        if (strlen($_POST['username']) < 6) {
            $errors[] = 'Sorry, your username must be at least 6 characters.';
        }
        if (strlen($_POST['username']) > 25) {
            $errors[] = 'Sorry, your username must be under 25 characters.';
        }
        if (preg_match("/\\s/", $_POST['username']) == true) {
            $errors[] = 'Your username must not contain any spaces.';
        }
        if (strlen($_POST['password']) < 6) {
            $errors[] = 'Sorry, your password must be at least 6 characters.';
        }
        if ($_POST['password'] !== $_POST['password_again']) {
            $errors[] = 'Sorry, your passwords do not match.';
        }
        if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false ) {
            $errors[] = 'Sorry, you did not provide a valid email address.';
        }
        if (email_exists($_POST['email']) === true ) {
            $errors[] = 'Sorry, the email \'' . $_POST['email'] . '\' is already registered to an account.';
        }
    }
}

?>
<h1>Register</h1>

<?php 
if (isset($_GET['success']) && empty($_GET['success'])) {
    echo "You have been registered successfully.";
} else {
    if (empty($_POST) === false && empty($errors) === true) {
        // register user
        $register_data = array(
            'username'      => $_POST['username'],
            'password'      => $_POST['password'],
            'first_name'    => $_POST['first_name'],
            'last_name'     => $_POST['last_name'],
            'email'         => $_POST['email'],
            'email_code'    => md5($_POST['username'] + microtime())
        );

        register_user($register_data);
        //header location not working *********************
        header('Location: register.php?success');
        exit();

    } else if (empty($errors) === false) {
        //error output
        echo output_errors($errors);
    }

?>
    <form action="" method="post">
        Register your account here, all fields are required.
        <ul>
            <li>
                Username: </br>
                <input type="text" name="username"/>
            </li>
            <li>
                Password: </br>
                <input type="password" name="password"/>
            </li>
            <li>
                Repeat Password: </br>
                <input type="password" name="password_again"/>
            </li>
            <li>
                First Name: </br>
                <input type="text" name="first_name"/>
            </li>
            <li>
                Last Name: </br>
                <input type="text" name="last_name"/>
            </li>
            <li>
                Email: </br>
                <input type="text" name="email"/>
            </li>
            <li>
                <input type="submit" value="Register"/>
            </li>
        </ul>
    </form>

<?php 
}
include 'includes/overall/footer.php'; 


?>
4

2 回答 2

0

最有可能的是,输出缓冲区在开发环境中处于打开状态,而在实时环境中处于关闭状态。此外,在实时环境中必须关闭向用户显示错误,否则确切的错误(在标题之前开始输出)将显示在浏览器中。

检查你的ini文件中的这些东西: http: //php.net/manual/en/outcontrol.configuration.php

于 2013-07-17T02:12:12.567 回答
0

请记住,必须在发送任何实际输出之前调用 header(),无论是通过普通 HTML 标记、文件中的空白行还是从 PHP 发送。使用 include() 或 require()、函数或其他文件访问函数读取代码并在调用 header() 之前输出空格或空行是一个非常常见的错误。使用单个 PHP/HTML 文件时也存在同样的问题。

于 2013-07-17T02:14:10.247 回答