0

我在注册页面上收到此错误:

Warning: Cannot modify header information - headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/signup/index.php:60) in /Applications/XAMPP/xamppfiles/htdocs/signup/index.php on line 75

这是我的代码,以便您查看:

<?php

include '../core/init.php';
logged_in_redirect();

if (empty($_POST) === false) {
    $required_fields = array('username', 'password', 'first_name', 'last_name', 'email');

    foreach ($_POST as $key => $value) {
        if(empty($value) && in_array($key, $required_fields) === true) {
            $errors[] = '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 (preg_match("/\\s/", $_POST['username']) == true) {
            $errors[] = 'Your username must not contain any spaces';
        }
        if (strlen($_POST['password']) < 5) {
            $errors[] = 'Your password must be at least 5 characters';
        }
        if (email_exists($_POST['email']) === true) {
        $errors [] = 'Sorry, the email \'' . $_POST['email'] . '\' is already in use.';

        }
    }
}


?>

<!DOCTYPE HTML>
 <html>
 <head>
         <title> Sem titulo </title>
     <link href="./resets.css" rel="stylesheet" type="text/css" />
     <link href="./style.css" rel="stylesheet" type="text/css" />
     <script src="js/ajax.js"></script>
     <script src="js/main.js"></script>

 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

</head>

 <body>
 <div class="wrapper">
     <div class="content">
         <div class="header">
             <div class="logo"><a href="./index.html"><img src="./images/ogo.png" border="0" /></a></div>
             <div class="login">Já tens login?  <a href="../login"><span>Login </span></a></div>
         </div>

         <div class="intro">            
              <div class="title">   Junta-te a nós! </div>

<?php

if (isset($_GET['success']) && empty($_GET['success'])) {
    echo 'You\'ve been successfully registered';
} else {

if (empty($_POST) === false && empty($errors) === true) {
    $register_data = array(
        'username'       => $_POST['username'],
        'password'       => $_POST['password'],
        'first_name'     => $_POST['first_name'],
        'last_name'      => $_POST['last_name'],
        'email'          => $_POST['email']
        );
    register_user($register_data);
    header ("Location: index.php?success");

    exit();

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


?>
<br>
<br>
    <form method='post' action='' >    

    <input type="text" class="sign-up-input" placeholder="Primeiro Nome" name="first_name" required pattern="^[a-z,A-Z]+$+~"><br>
    <input type="text" class="sign-up-input" placeholder="Último Nome" name="last_name" required pattern="^[a-z,A-Z]+$"><br>
    <input type="text" class="sign-up-input" placeholder="O teu Email" name="email" required pattern="([\w\-\.]+)@((\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)+)([a-z,A-Z]{2,4}))"><br>
    <input type="text" class="sign-up-input" placeholder="Username" name="username" required><br>
    <input type="password" class="sign-up-input" placeholder="Password" name="password" MinimumLength="6" required pattern="^[\s\S]{6,256}$"><br>
    <input type="submit" value="Regista-te!" class="sign-up-button">

    </form>
<?php
}
?>
<br>

    </div>

        </div>
</div>



         <div class="footer">
             <?php include '../core/include/copyright.php'; ?>
                 <ul>
                     <li><a href="">Contacto </a></li>
                     <li><a href="./businesses/index.html">Informação </a></li>
                     <li><a href="./privacy/index.html">Politica de Privacidade </a> </li>
                     <li><a target="_blank" href="#">Termos e Condições  </a></li>
                     <li><a target="_blank" href="">Empregos</a></li>
                 </ul>
        </div>


 </html>

有人可以帮我吗?提前谢谢

4

2 回答 2

3

需要在输出其他任何内容之前设置标题。

您在发送 html 代码后设置标题。

移动 if else 语句if (empty($_POST) === false && empty($errors) === true) { 之前<!DOCTYPE HTML>

于 2013-07-15T23:28:59.073 回答
0

在输出上述其他内容后,您无法修改标题信息。您可以尝试输出缓冲: http: //php.net/manual/en/function.ob-start.php

于 2013-07-15T23:32:16.797 回答