youyu:91501

通过 post 提交登录信息到isLogin.php,在isLogin.php页面创建cookie

image.png

(1)在isLogin.php页面通过post获取表单提交的数据    

        $userName 获取登录名

        $password 获取密码

(2)创建两个cookie,不设置有效期

                        一个cookie名称是userName,同时设置值为 $userName

                        另一个cookie名称是password ,同时设置值为 $password 

login.php:

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"></meta>
	<title>登录_存cookie</title>
	<style type="text/css">
		 *{
	        padding:0;
	        margin:0;
	      }
	      #main{
	          width:400px;
	          background-color:#FFF;
	          border-radius:5px;
	          overflow:hidden;
	          box-shadow: 0px 0px 5px #333333;
	          position:absolute;
	          left:50%;
	          top:50%;
	          transform:translate(-50%,-50%);
	          padding: 20px 20px 20px 20px;
	          height:300px;
	      }
	      .vip{
	          background-color:#E0E2EF;
	          width:100%;
	          height:100%;
	          position:absolute;
	          top:0;
	          bottom:0;
	          left:0;
	          right:0;
	          background:#0b1546;
	      }
	      .denglu{
	      	font-size: 22px;box-sizing: border-box;color: #333333;height:80px;line-height:60px;text-align: center;
	      }
	      .cont{
	      	width:250px;height:70px;font-size: 16px;margin:auto;
	      }
	      .title{
	      	float:left;
	      	height:35px;
	      	line-height: 35px;
	      	font-size: 14px;
	      }
	      .write{
	      	float:right;
	      }
	      .txt{
	      	z-index: 2;
	      	padding-left: 10px;
	      	color: #333333;
	      	width: 160px;
	      	height: 35px;
	      	border: 0;
	      	border-bottom: 1px solid #cccccc;
	      	border-top: 1px solid #ffffff;
	      	border-left: 1px solid #ffffff;
	      	border-right: 1px solid #ffffff;
	      	background: #FFF;
	      	border-radius: 5px
	      }
	      .txt:focus{border: 1px solid dodgerblue;}
	      .btn{
	      	border:0;
	      	cursor: pointer;
	      	width: 250px;
	      	text-align: center;
	      	height: 40px;
	      	line-height: 40px;
	      	background-color: 
	      	dodgerblue;
	      	border-radius: 5px;
	      	margin:auto;
	      	color: white;
		  }
	</style>
</head>
<body>
<div class="vip">
	<div id="main">
		<div class="denglu">登录</div>
	    <form method="post" action="isLogin.php">
		    <div class="cont">
		      <div class="title">登录名:</div>
		      <div class="write"><input type="text" id="userName" name="userName" class="txt" placeholder="请输入用户名" /></div>
		    </div>
		    <div class="cont">
		      <div class="title">密码:</div>
		      <div class="write"><input type="password" id="password" name="password" class="txt" placeholder="请输入密码" /></div>
		    </div>
		    <div class="cont">
		      <div><input type="submit" value="登录" class="btn"/></div>
		    </div>
	    </form>
	</div>
</div>
</body>
</html>

islogin.php:

<?php 
header("content-type:text/html;charset=utf-8");

// 通过POST获取表单提交的数据
$userName = $_POST['userName'] ?? '';
$password = $_POST['password'] ?? '';

// 创建两个cookie,不设置有效期(会话cookie)
setcookie('userName', $userName);
setcookie('password', $password);

// 显示接收到的数据(可选)
echo "用户名: " . htmlspecialchars($userName) . "<br>";
echo "密码: " . htmlspecialchars($password) . "<br>";
echo "Cookie已设置";
?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值