|
本帖最后由 yeyue910107 于 2011-6-1 18:25 编辑
个简单的注册表单:
<div id = 'resuMsg'>
<?php echo $resuMsg; ?>
</div>
<hr />
<div id = 'registerForm'>
<form action = '' method = 'post'>
<label>用户名:</label><input type = 'text' name = 'username' /><br />
<label>密码:</label><input type = 'password' name = 'password' /><br />
<label>重复密码:</label><input type = 'password' name = 'password2'/><br />
<input type = 'submit' value = '提交' />
</form>
</div>
控制器里的register.php如下:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Register extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('user_model');
}
public function index()
{
$username = $this->input->post('username');
$password = $this->input->post('password');
$password2 = $this->input->post('password2');
$username = trim($username);
$password = trim($password);
$password2 = trim($password2);
$password_md5 = md5($password);
$show['resuMsg'] = NULL;
if($username != '')
{
//don't need to check sql inject
if(! preg_match("/^[_0-9a-zA-Z]{2,32}$/",$username))
{
$show['resuMsg'] = 'illegal username';
}
else if($this->user_model->checkUserExist($username) == 1)
{
$show['resuMsg'] = 'user exist';
}
else if($password == '')
{
$show['resuMsg'] = 'password is empty';
}
else if($password != $password2)
{
$show['resuMsg'] = 'password not same';
}
else
{
$resu = $this->user_model->addUser($username,$password_md5);
$resu == 1 ? $show['resuMsg'] = 'Success' : $show['resuMsg'] = 'failed';
}
}
$this->load->view('title');
$this->load->view('regsiter',$show);
$this->load->view('foot');
}
}
apache里用.htaccess设置了rewrite规则,但现在遇到了一个奇怪的问题,直接在/register显示的页面里提交表单之后只是重载了页面而没有注册,但如果在地址栏里输入/index.php/register,在显示的页面里提交表单可以注册成功,求助!!!
|
|