<?php
class Test_m extends CI_Model
{
function __construct()
{
parent::__construct();
$this->load->database();
}
function user_insert($arr)
{
$this->db->insert('user',$arr);
}
function user_update($id,$arr)
{
$this->db->where('uid',$id);
$this->db->update('user',$arr);
}
function user_del($id)
{
$this->db->where('uid',$id);
$this->db->delete('user');
}
function user_select($uname)
{
$this->db->where('uname',$uname);
$this->db->select('*');
$query=$this->db->get('user');
return $query->result();
}
}
?>
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login extends CI_Controller
{
function index()
{
$this->load->view('login');
}
function checklogin()
{
$this->load->model("test_m");
$user=$this->test_m->user_select($_POST['uname']);
if($user)
{
if($user[0]->upass==$_POST['upass'])
{
echo '密码正确';
$this->load->library('session');
$arr=array('uid'=>$user[0]->uid);
$this->session->set_userdata($arr);
echo '<br />';
echo $this->session->userdata('uid');
}
else
{
echo '密码不正确';
}
}
else
{
echo '用户名不存在';
}
}
function checksession()
{
$this->load->library('session');
if( $this->session->userdata('uid'))
{
echo '已经登录';
}
else
{
echo '没有登录';
}
}
function loginout()
{
$this->load->library('session');
$this->session->unset_userdata('uid');
}
}
<html>
<center><h1>用户登录页面</h1></center>
<form action="/index.php/login/checklogin" method="post">
<center>
<ul style="list-style:none">
<li>用户名</li>
<li><input name="uname" type="text" /></li>
<li>密码</li>
<li><input name="upass" type="password" /></li>
<li><input name="sub" type="submit" value="提交" /></li>
</ul>
</center>
</form>
</html>
A Database Error OccurredUnable to connect to your database server using the provided settings. Filename: C:\AppServ\www\system\database\DB_driver.php Line Number: 125
|