表单内容(demo5.php):
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<form method="post" action="demo7.php">
账号:<input type="text" name="username" /><br />
<input type="submit" value="提交" name="send" />
</form>
表单验证并创建cookie(demo6.php):
<?php
if(isset($_POST['username']) && $_POST['username']=='cck'){
setcookie('name','曹昌魁');
header('location:demo8.php');
}else {
header('location:demo6.php');
}
?>
登陆成功后跳转至页面:demo6.php:
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<?php
if(isset($_COOKIE['name'])){
echo '欢迎光临!'.$_COOKIE['name'];
}else {
echo '非法登录';
}
?>