|
控制器:
PHP复制代码 <?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复制代码 <?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;
}
}
?> 复制代码
视图:
HTML复制代码 <!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 |
|