Database and all code display

Database display:

sql execution:

CREATE TABLE `user` (

`id` int( 4) NOT NULL auto_increment,

`username` varchar(33) NOT NULL,

`password` varchar(33) NOT NULL,

PRIMARY KEY (`id` )

) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

微信图片_20180227163625.png


required code File:

微信图片_20180227164115.png

The code is shown below:

##register.html:

    Title 

用户:
密码:
确认密码:

#add.php:

query("SELECT password FROM user WHERE username = "."'$username'"); $rs=$result->fetch_row(); if(!empty($rs)){ $data = array( array('code' => 1, 'message' => '用户已存在,请重新注册'), ); echo json_encode($data); //数组转json格式 }else { $mysqli = new mysqli('localhost', 'root', 'root', 'student'); $sql = "INSERT INTO user (username,password) VALUES ('$_GET[username]', '$_GET[password]')"; $rs = $mysqli->query($sql); if (!$rs) { $data = array( array('code' => 2, 'message' => '注册失败,请重新注册'), ); echo json_encode($data); } else { $data = array( array('code' => 3, 'message' => '注册成功!跳转到登录页面。。。'), ); echo json_encode($data); } }

login.html:

    Title 

用户:
密码:

success.php:

query("SELECT password FROM user WHERE username = "."'$username'"); $rs=$result->fetch_row(); if (!empty($rs)){ if ($password != $rs[0]) { $data = array( array('code' => 1, 'message' => '密码错误,请重新登录'), ); echo json_encode($data); }else{ $expire=3600; ini_set('session.gc_maxlifetime', $expire);//保存1小时 if (empty($_COOKIE['PHPSESSID'])) { session_set_cookie_params($expire); session_start(); }else{ session_start(); setcookie('PHPSESSID', session_id(), time() + $expire); } if(isset($_SESSION['username'])){ $data = array( array('code' => 2, 'message' => '您已经登入了,请不要重新登入','session'=>$_SESSION['username']), ); echo json_encode($data); }else{ $_SESSION['username']=$_GET['username']; $data = array( array('code' => 3, 'message' => '登录成功','session'=>$_SESSION['username']), ); echo json_encode($data); } } }else{ $data = array( array('code' => 4, 'message' => '没有此用户,请重新登录'), ); echo json_encode($data); }

logout.php:

alert('注销成功!');location.href='login.html';"; }else{ echo ""; }


Continuing Learning
||
Title

用户:
密码:
确认密码:
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!