|
PHP复制代码
class MY_Controller extends CI_Controller {
function __construct ()
{
parent ::__construct ();
session_start();
$this->load->helper('url');
$this->output->enable_profiler(TRUE);
}
function login ()
{
if(!$_SESSION['username'])
{
if($this->input->post('login'))
{
$username = $this->input->post('username');
$password = $this->input->post('password');
if ($username && $password)
{
$this->load->model('users_model');
$user_info = $this->users_model->get_user($username, 'Password')->row_array();
if($user_info)
{
if( $user_info['Password'] == md5( $password ) )
{
$this->users_model->set_user_session($username);
return true;
}
else
$data['error'] = '密码错误!';
}
else
$data['error'] = '用户不存在!';
}
}
$this->load_view('login.php', $data);
$this->output->_display ();
exit;
}
return true;
}
function load_view ($main_file, $data = '')
{
$this->load->view('templates/header.php', $data);
if(is_array($main_file))
{
foreach ($main_file as $file)
$this->load->view($file);
}
else
$this->load->view($main_file);
$this->load->view('templates/footer.php');
}
}
复制代码
只要想说的是的login()方法!
使用例子,
PHP复制代码
class test() extends MY_Controller()
{
function test()//如果这个页面需要登陆才可以访问,只需要把$this->login()即可!
{
$this->login();
}
}
复制代码
|
|