song4674 发表于 2010-7-5 15:24:13

这是bom错误吗?如何解决

控制器:
<?php
/*
* Created on 2010-7-5
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
class Login extends Controller
{
function Login()
{
       parent::Controller();
       $this->load->database();
       $this->load->helper('url');
}
function index()
{
   $this->load->helper('form');
   $data['title']="登录页面";
   $this->load->view('login', $data);
}
function chk_login()
{
   $arr=array(
         'user'=> $this->input->xss_clean($this->input->post('user')),
         'pass'=> $this->input->xss_clean($this->input->post('pass'))
      );
   $this->load->model('MLogin','',TRUE);
   $this->MLogin->chk_login();
   //redirect('CodeIgniter/test/view','refresh');
if(isset($data)&&$data['pass']==$arr['pass'])
{
   echo "登录成功";
   redirect('CodeIgniter/test/viewUsers','refresh');
}else
{
   echo "用户名密码错误,请重试";
   redirect('CodeIgniter/login/','refresh');
}
}
}
?>

模型:<?php
/*
* Created on 2010-7-5
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
class MLogin extends Model{
    function MLogin(){
      parent::Model();
         $this->load->helper('url');
         $this->load->database();
    }
    function chk_login(){
   $arr=array(
         'user'=> $this->input->xss_clean($this->input->post('user')),
         'pass'=> $this->input->xss_clean($this->input->post('pass'))
      );
         $this->db->where('user', $arr['user']);
      $data = $this->db->get('admin');
         return $data;
    }
}
?>

视图:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $title;?></title>
</head>
<body>
<?php
/**
* form表单
*/
echo form_open('CodeIgniter/login/chk_login');
echo form_label('帐号','user');
echo "<br>";
$ndata = array('name' => 'user', 'id' => 'user', 'size' => '40');
echo form_input($ndata);
echo "<br>";
echo form_label('密码','pass');
echo "<br>";
$adata = array('name' => 'pass', 'id' => 'pass', 'size' => '40');
echo form_input($adata);
echo "<br>";
echo form_submit('submit','登录');
echo form_close();
?>
</body>
</html>

报错:
鐢ㄦ埛鍚嶅瘑鐮侀敊璇紝璇烽噸璇?div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;"> A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at E:\wamp\www\CodeIgniter\system\application\controllers\login.php:37)
Filename: helpers/url_helper.php
Line Number: 539

song4674 发表于 2010-7-5 15:43:57

Message: Cannot modify header information - headers already sent by (output started at E:\wamp\www这个错误见过好几次了,可就是不知道是哪错了,有人能帮我下吗?

Hex 发表于 2010-7-5 16:08:07

E:\wamp\www\CodeIgniter\system\application\controllers\login.php:37
第 37 行已经输出内容了,看看这个 37 是什么。
你这个和 BOM 无关。

song4674 发表于 2010-7-5 16:22:50

37行是这句:
echo "用户名密码错误,请重试";
应该不会有错吧这句

visvoy 发表于 2010-7-5 17:06:20

手册有提到:redirect()
注意:由于此函数需要处理header头文件,因此它的使用必须在任何输出给浏览器的内容前。

Hex 发表于 2010-7-5 18:11:49

回复 4# song4674


    这不是说你这句话错了,而是这句话不应该写在这里。
http header 输出以前不能输出任何东西,这是 HTTP 协议规定的,具体请查看 HTTP 协议。

song4674 发表于 2010-7-5 22:24:34

嗯,好的。谢谢各位的热心帮助
页: [1]
查看完整版本: 这是bom错误吗?如何解决