新泰威海百度快照优化公司-2019张家港中考二模

首页

AD联系:507867812

新泰威海百度快照优化公司

时间:2019-11-20 06:41:47 作者:湖北体彩迈入“百亿俱乐部”... 浏览量:81336

新泰威海百度快照优化公司

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

Codeigniter注册登录代码示例Codeigniter注册登录代码示例Codeigniter注册登录代码示例Codeigniter注册登录代码示例Codeigniter注册登录代码示例Codeigniter注册登录代码示例,见下图

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

,见下图

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

Codeigniter注册登录代码示例Codeigniter注册登录代码示例,如下图

Codeigniter注册登录代码示例

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

Codeigniter注册登录代码示例

如下图

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

,如下图

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

,见图

新泰威海百度快照优化公司Codeigniter注册登录代码示例

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

Codeigniter注册登录代码示例

Codeigniter注册登录代码示例

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

Codeigniter注册登录代码示例

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

Codeigniter注册登录代码示例

Codeigniter注册登录代码示例

Codeigniter注册登录代码示例

Codeigniter注册登录代码示例Codeigniter注册登录代码示例Codeigniter注册登录代码示例

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

Codeigniter注册登录代码示例Codeigniter注册登录代码示例Codeigniter注册登录代码示例

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

Codeigniter注册登录代码示例Codeigniter注册登录代码示例

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

Codeigniter注册登录代码示例

新泰威海百度快照优化公司

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

Codeigniter注册登录代码示例Codeigniter注册登录代码示例Codeigniter注册登录代码示例Codeigniter注册登录代码示例

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

Codeigniter注册登录代码示例。

Codeigniter注册登录代码示例

1.

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

Codeigniter注册登录代码示例Codeigniter注册登录代码示例

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

Codeigniter注册登录代码示例

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

Codeigniter注册登录代码示例

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

Codeigniter注册登录代码示例

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

2.

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

Codeigniter注册登录代码示例Codeigniter注册登录代码示例

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

Codeigniter注册登录代码示例

3.

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

Codeigniter注册登录代码示例Codeigniter注册登录代码示例

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

Codeigniter注册登录代码示例

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

Codeigniter注册登录代码示例

4.

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

Codeigniter注册登录代码示例

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

Codeigniter注册登录代码示例

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

Codeigniter注册登录代码示例

本示例Codeigniter注册登录代码源自一个codeigniter的项目,现分享下~

由于使用了 Active Record 类,一般数据库操作只有两层,即是C和V

controllers/login.php文件:

复制代码 代码如下:<?phpclass Login extends CI_Controller {private $pass = '';public function __construct() { parent::__construct (); $this->load->helper ( array ( 'form', 'url' ) ); $this->load->library('session');}public function index() { $this->load->view ( 'login' );}public function formsubmit() { $this->load->library ( 'form_validation' ); $this->form_validation->set_rules ( 'username', 'Username', 'required' ); $this->form_validation->set_rules ( 'password', 'Password', 'required' ); if ($this->form_validation->run () == FALSE) { $this->load->view ( 'login' ); } else { if (isset ( $_POST ['submit'] ) && ! empty ( $_POST ['submit'] )) { $data = array ( 'user' => $_POST ['username'], 'pass' => md5($_POST ['password']) ); $newdata = array( 'username' => $data ['user'] , 'userip' => $_SERVER['REMOTE_ADDR'], 'luptime' =>time() ); if ($_POST ['submit'] == 'login') { $query = $this->db->get_where ( 'uc_user', array ( 'user' => $data ['user'] ), 1, 0 ); foreach ( $query->result () as $row ) { $pass = $row->pass; } if ($pass == $data ['pass']) { $this->session->set_userdata($newdata); $this->load->view ( 'usercenter', $data ); } } else if ($_POST ['submit'] == 'register') { $this->session->set_userdata($newdata); $this->db->insert ( 'uc_user', $data ); $this->load->view ( 'usercenter', $data ); } else { $this->session->sess_destroy(); $this->load->view ( 'login' ); } } }}}

views/login.php文件:

复制代码 代码如下:<html><?php echo validation_errors(); ?><?php echo form_open('login/formsubmit'); ?><table><tr><td>用户名</td><td><input type="text" name="username"></td></tr><tr><td>密码</td><td><input type="password" name="password"></td></tr><tr><td><input type="submit" name="submit" value="login"></td><td><input type="submit" name="submit" value="register"></td></tr></table></form></html>

sql语句:

uc_user:复制代码 代码如下: CREATE TABLE `uc_user` ( `id` int(11) unsigned zerofill NOT NULL AUTO_INCREMENT, `user` varchar(20) NOT NULL, `pass` char(32) NOT NULL, `role` enum('root','normal') NOT NULL DEFAULT 'root', `del` decimal(1,0) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

Codeigniter注册登录代码示例。新泰威海百度快照优化公司

展开全文
相关文章
合乐888特约总代理

Codeigniter注册登录代码示例

奥门赌场男人福利网站

Codeigniter注册登录代码示例....

乐国际老虎机手机版

Codeigniter注册登录代码示例....

维多利亚老品牌官网

Codeigniter注册登录代码示例....

wanjie.com 电子邮件

Codeigniter注册登录代码示例....

相关资讯
热门资讯