Rumah > Soal Jawab > teks badan
<?php /** * Created by PhpStorm. * User: KEVIN * Date: 2017-11-30 * Time: 17:00 */ if(isset($_GET['action'])) { if ($_GET['action'] == 'login') { if ($_POST['name'] == 'admin' && $_POST['pwd'] == 123456) { setcookie('userName', $_POST['name'], time() + 3600 * 24); header('Location:index.php'); } else { echo '<script>alert("用户名或密码不对!");</script>'; } } elseif ($_GET['action'] == 'logout') { setcookie('username', '', time() - 3600);//注销cookie } } ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>用户登陆</title> </head> <body> <form action="<?php echo $_SERVER['PHP_SELF'];?>?action=login" methond="post"> <fieldset> <legend>用户登陆</legend> <lable for="name">用户名:</lable> <input type="text" name="name" id="name"> <lable for="pwd">密码:</lable> <input type="password" name="pwd" id="pwd"> <input type="submit" value="提交"> </fieldset> </form> </body> </html>