首页 > 代码库 > Session控制登陆
Session控制登陆
Session控制登陆
<html><head> <meta http-equiv="content-type" content="text/html;charset=utf-8"/> <script> function on_load() { console.log("welcome!"); } function on_focus() { var name = document.getElementsByName(‘name‘); if ("请输入用户名:" === name[0].value) { name[0].value = http://www.mamicode.com/‘‘; } console.log(name[0].value); } function check(){ var name = document.getElementsByName(‘name‘); var password = document.getElementsByName(‘password‘); if("请输入用户名:" == name[0].value.replace(/[ ]/g,‘‘)){ alert("用户名错误!"); return false; } if("" == name[0].value.replace(/[ ]/g,‘‘)){ alert("用户名不能为空"); return false; } if("" == password[0].value.replace(/[ ]/g,‘‘)){ alert("密码不能为空"); return false; } } </script></head><body onl oad="on_load()"><div> <form action="#" method="get" name="myForm"> <table> <tr> <td>用户名:</td> <td><input id="name" name="name" type="text" value="http://www.mamicode.com/请输入用户名:" onfocus="on_focus()"/></td> </tr> <tr> <td>密码</td> <td><input type="password" name="password" value=""/></td> </tr> <tr> <td colspan="2"><input name="submit" type="submit" value="http://www.mamicode.com/登陆" style="vertical-align: center" onclick="check()"/></td> </tr> </table> </form></div></body></html><?php$mysqli = new mysqli(‘localhost‘, ‘root‘, ‘123456‘, ‘rentalstore‘);if(!isset($_GET[‘submit‘])){ exit;}session_start();$loginSession = $_COOKIE[‘PHPSESSID‘];if(isset($_SESSION[$_GET[‘name‘]]) and $loginSession == $_SESSION[$_GET[‘name‘]]){ header("Location:https://www.baidu.com");}$sql = ‘select * from user where name ="‘.$_GET[‘name‘].‘"‘;$result = $mysqli->query($sql)->fetch_assoc();if($_GET[‘password‘] == $result[‘password‘]){ $_SESSION[$_GET[‘name‘]] = $loginSession; header("Location:https://www.baidu.com");}else{ echo "登陆失败";}
Session控制登陆
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。