PHP cannoy modify header information - headers already sent by ....

我采用的是MVC模式的写法,代码和html分离的写法

<?php
require ‘../mysql_connect.php‘;
require(‘../model/functions.php‘);
include_once ‘../views/login.html.php‘;
 if ($_SERVER[‘REQUEST_METHOD‘] == ‘POST‘) {   // 处理表单
 	if (isset($_POST[‘login_submit‘])) {

        $role = $_POST[‘role‘];
 		$username = $_POST[‘username‘];
        $passwd = $_POST[‘p‘];

    if( user_login($pdo,$role,$username,$passwd) ){
        setcookie(‘userName‘,$name);
        setcookie(‘password‘,$psw);
        header("location: index.php");
    }else{
        echo "<script>alert(‘输入信息错误,登录失败‘);</script>";
    }

 	}elseif (isset($_POST[‘get_password‘])) {

        $email = $_POST[‘email‘];
        user_register($pdo,$email);
 	}
}

  

我在一个页面内写了两个form表单,但是两个表单都是提交到同一个PHP文件处理,到时提交第二个表单时就一直报这种错误,

 解决方法:

只需要将第四行的html代码移到最后

原文地址:https://www.cnblogs.com/ryanzheng/p/8224025.html

时间: 2024-07-30 21:14:36

PHP cannoy modify header information - headers already sent by ....的相关文章

PHP错误Warning: Cannot modify header information - headers already sent by解决方法

这篇文章主要介绍了PHP错误Warning: Cannot modify header information - headers already sent by解决方法,需要的朋友可以参考下 今天在测试以下代码时遇到该错误: 复制代码代码如下: session_start();$_SESSION['username']=$username;echo "<script language='javascript'>location.href='../admin.php';</sc

出现Warning: Cannot modify header information - headers already sent by ..的解决办法

这个错误的出现,原因是: 出这个错误是因为 header('Content-Type:text/html;charset= UTF-8');发送头之前不能有任何输出. 检查了下我的输出,错误信息如下: Warning: Cannot modify header information - headers already sent by (output started at /data/home/qxu1084910324/htdocs/bw_feature.php:1) in /data/hom

关于报错:Warning: Cannot modify header information - headers already sent by (output started at

8月5日,第一个项目即将完成,测试时,发现登录功能会出现小问题:记住密码的时候会报错 Warning: Cannot modify header information - headers already sent by (output started at 经过再三在百度上查询,终于查到错误的关键原因:[setcookie之前不可以有html标签内容].导致出现这种错误的方式有很多种,但惟独这种解释最让我理解. (因为百度知道的内容不可以复制了,只能贴出地址,有详细解释)地址[http://z

PHP程序错误Warning: Cannot modify header information - headers already sent by ....

在使用phpmywind程序时出现的问题Warning: Cannot modify header information - headers already sent by .... 检查了许久,居然是编码的问题 请将单纯的utf-8格式改为utf-8无BOM编码格式 在NOTEPAD++的格式菜单可以修改 或者其它工具的

Cannot modify header information - headers already sent by出错的原因

<?php ob_start(); setcookie("username","送家",time()+3600); echo "the username is:".$HTTP_COOKIE_VARS["username"]."\n"; echo "the username is:".$_COOKIE["username"]."\n"; pri

PHP:Cannot modify header information - headers already sent by出错解决

<?php ob_start();setcookie("username","test",time()+3600);echo "the username is:".$HTTP_COOKIE_VARS["username"]."\n";echo "the username is:".$_COOKIE["username"]."\n";print

Warning: Cannot modify header information - headers already sent by (output started at

一般来说在header函数前不能输出html内容,类似的还有setcookie() 和 session 函数,这些函数需要在输出流中增加消息头部信息.如果在header()执行之前有echo等语句,当后面遇到header()时,就会报出 “Warning: Cannot modify header information - headers already sent by ....”错误.就是说在这些函数的前面不能有任何文字.空行.回车等,而且最好在header()函数后加上exit()函数.例

php5.6,Ajax报错,Warning: Cannot modify header information - headers already sent in Unknown on line 0

php5.6ajax报错 Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead. in Unkno

Cannot modify header information - headers already sent by

有时候你在使用 header("Location: http://localhost/myblog/index.php/manager/listview");的时候会出现这个问题,可是也许你是从别处拷贝过来的别处都没有出现过这个问题,这时候你就很疑惑了注意很可能是因为你在前面输出了一个echo的缘故或者你在前面加上一个ob_start():可能够解决