Php 警告:无法修改标题信息

Php 警告:无法修改标题信息,php,Php,我在注册页面上遇到此错误: 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 这是我的代码,您可以查看: <?p

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

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>

塞姆·提图洛
查登登入?
nós军政府!









有人能帮帮我吗?

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

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

Move if else语句
if(empty($\u POST)==false&&empty($errors)==true){

在输出任何其他内容之前,需要设置Before

标题

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

Move if else语句
if(empty($\u POST)==false&&empty($errors)==true){

之前,输出上述内容后,您不能修改标题信息。您可以尝试输出缓冲:

输出上述内容后,您不能修改标题信息。您可以尝试输出缓冲:

快速回答删除:行
标题(“Location:index.php?success”);
长答案,了解
无法修改标题的错误查看此代码:
if(isset($\u GET['success'))&&empty($\u GET['success')){
永远不要信任GET变量中的数据。快速答案删除:line
标题(“Location:index.php?success”)
long answer,了解
无法修改标题
错误查看此代码:
if(设置($\u GET['success'))和空($\u GET['success')){
永远不要信任GET变量中的数据。我该如何做才能在用户注册时重定向?答案更新,希望这会有帮助。谢谢!它帮助了很多人。我该如何做才能在用户注册时重定向?答案更新,希望这会有帮助。谢谢!它帮助了很多人输出缓冲是一个选项,但这里不需要逻辑只需要向上移动,正如Sumoanand所建议的。输出缓冲是一个选项,但在这里不需要。逻辑只需要向上移动,正如Sumoanand所建议的。