dongshen9686 2013-07-15 23:25
浏览 31
已采纳

警告:无法修改标题信息[重复]

I am getting this error on my register page:

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

Here is my code so that you can take a look:

<?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>

Can someone please help me out??Thanks in advance

</div>
  • 写回答

2条回答 默认 最新

  • douwen7516 2013-07-15 23:28
    关注

    Header needs to be set before outputting anything else.

    You are setting header after sending the html code.

    Move if else statement if (empty($_POST) === false && empty($errors) === true) { Before <!DOCTYPE HTML>

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装