Login.php
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Login</title> <script> setInterval( function(){with(new Date)a.innerHTML=toLocaleString()+"星期"+"天一二三四五六".charAt(getDay());} ,1000) </script> <style> body{ font-family:Arial, Helvetica, sans-serif; color:#333333; font-size:0.8em; } p{ margin:0px 0px 10px 0px; } #user, #pass{ width:170px; } #box{ width:250px; margin:100px auto 0px auto; background:#F0F0F0; padding:15px; } #a{ width:210px; margin:0px auto ; background:#F0F0F0; padding:10px; } </style> </head> <body> <div id="a"></div> <div id="box"> <form action="checklogin.php" method="post"> <p><label for="user">Username:</label> <input id="user" name="user" type="text" /></p> <p><label for="pass">Password:</label> <input id="pass" name="pass" type="password" /></p> <p><input type="submit" value="Login" /></p> <input type="submit" name="register" value="Register"/> </form> </div> </body> </html>
CheckLogin.php
<?php //Start session session_start(); if(isset($_POST['register'])){ header("Location: Register.php"); exit; } //Then we retrieve the posted values for user and password. $user = $_POST['user']; $pass = $_POST['pass']; $hashpass = md5($pass); //Users defined in a SQLite database $db = new SQLite3('db/mysqlitedb.db'); $result = $db->query("SELECT COUNT(*) AS count FROM users2 WHERE username = '$user' AND password = '$hashpass'"); $row = $result->fetchArray(); if ($row[0] > 0) { //If user and pass match any of the defined users $_SESSION['loggedin'] = true; header("Location: index.php"); }; //If the session variable is not true, exit to exit page. if(!$_SESSION['loggedin']){ header("Location: login.php"); exit; }; ?>
Register.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript" > //检查是否都符合 注册 function check_reg() { if(check_len() && check_pass() && check_email() && check_qq()) { return true; }else{ return false; } } </script> <script type="text/javascript" > //检查密码长度不能少于6 function check_len(thisObj){ if(thisObj.value.length==0) { document.getElementById('show_pass').innerHTML="密码不能为空"; return false; }else{ if (thisObj.value.length<6) { document.getElementById('show_pass').innerHTML="密码长度不少于6"; return false; } document.getElementById('show_pass').innerHTML=""; return true; } } </script> <script type="text/javascript" > //检查俩次密码输入是否一致 function check_pass(thisObj){ var psw=document.getElementById('pass'); if(psw.value.length==0) { document.getElementById('show_pass').innerHTML="密码不能为空"; return false; }else{ document.getElementById('show_pass').innerHTML=""; if (thisObj.value!=psw.value) { document.getElementById('show_repass').innerHTML="两次密码输入不正确"; return false; } document.getElementById('show_repass').innerHTML=""; return true; } } </script> <script type="text/javascript" > //检查email是否正确 function check_email(thisObj){ var reg=/^([a-zA-Z\d][a-zA-Z0-9_]+@[a-zA-Z\d]+(\.[a-zA-Z\d]+)+)$/gi; var rzt=thisObj.value.match(reg); if(thisObj.value.length==0){ document.getElementById('show_e').innerHTML="Email不能为空"; return false; }else{ if (rzt==null) { document.getElementById('show_e').innerHTML="Email地址不正确"; return false; } document.getElementById('show_e').innerHTML=""; return true; } } </script> <script type="text/javascript"> //检查qq格式是否正确 function check_qq(thisObj){ var qq=document.getElementById('qq').value; var reg=/^\d+$/; if(qq.search(reg)) { document.getElementById('show_qq').innerHTML=" QQ 只能为数字"; return false; }else{ document.getElementById('show_qq').innerHTML=""; return true ; } } </script> <script> setInterval( function(){with(new Date)a.innerHTML=toLocaleString()+"星期"+"天一二三四五六".charAt(getDay());} ,1000) </script> <title>Login</title> <style> body{ font-family:Arial, Helvetica, sans-serif; color:#333333; font-size:0.8em; } p{ margin:0px 0px 10px 0px; } #user, #pass{ width:170px; } #a{ width:210px; margin:0px auto ; background:#F0F0F0; padding:15px; } #box{ width:200px; margin:100px auto 0px auto; background:#F0F0F0; padding:15px; } </style> </head> <body onLoad="time()"> <div id="box"> <form action="checkRegister.php" method="post"> <p><label for="user">用户名:</label> <input id="user" name="user" type="text" /></p> <p><label for="pass">密 码:</label> <input id="pass" name="pass" type="password" onblur="check_len(this)"/><span id="show_pass" style="color:red;"></span></p> <p><label for="pass2">确认密码:</label> <input id="repass" name="repass" type="password" onblur="check_pass(this)" /><span id="show_repass" style="color:red;"></span></p> <p><label for="truename">真实姓名:</label> <input id="truename" name="truename" type="text" /> </p> <p><label for="email">Email</label> <input id="email" name="email" type="text" onblur="check_email(this)"/><span id="show_e" style="color:red;"></span></p> <p><label for="phone">电 话</label> <input id="phone" name="phone" type="text" /></p> <p><label for="qq">QQ号</label> <input id="qq" name="qq" type="text" onblur="check_qq(this)"/><span style="color:red;" id="show_qq"></span></p> <table width="200" border="0"> <tr> <td><input name="submit" type="submit" value="注册" /></td> <td><input name="submit" type="reset" value="重置" /></td> </tr> </table> <div id="a"></div> </form> </div> </body> </html>
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>Login</title> <style> #a{ width:210px; margin:0px auto ; background:#F0F0F0; padding:10px; } body{ font-family:Arial, Helvetica, sans-serif; color:#333333; font-size:0.8em; } #div1{ width:243px; height:35px; margin:10px auto 0px auto; padding:15px; } #div2{ width:250px; height:35px; margin:30px auto 0px auto; padding:15px; } </style> <body> <?php //Start session session_start(); //Then we retrieve the posted values for user and password. $user = $_POST['user']; $pass = $_POST['pass']; $realname = $_POST['truename']; $Email = $_POST['email']; $phone= $_POST['phone']; $QQ = $_POST['qq']; $db = new SQLite3('db/mysqlitedb.db'); $result = $db->query("SELECT COUNT(*) AS count FROM users2 WHERE username = '$user'"); $row = $result->fetchArray(); if ($row[0] > 0) { //If user exists return register header("Location: register.php"); exit; } //$db = new PDO('sqlite:users.sqlite'); $hashpass = md5($pass); $db->exec("INSERT INTO users2(username,password,realname,Email,phone,QQ) VALUES ('$user','$hashpass','$realname','$Email','$phone','$QQ')"); $db->close(); echo "你的用户名"; echo $user; echo "已成功注册!!"; //header("Location:login.html"); ?> <meta http-equiv="refresh" content="3;url=login.php"> </head> <body> <div id="div2"> <p>3秒后将跳转到登陆页面</p> <div> <div id="a"></div> </body> </html>