我登录时有一个登录页面,进程页面设置了一个 cookie,我想使用这个 cookie 下次自动登录。Cookie 设置在浏览器上,我可以看到它,但是当我想在登录页面上使用它时,cookie 是空的(浏览器仍然有它,我可以看到它)
浏览器:Mozilla
目录:
index.php (login page) --> in root /
include-function --> /functions/include-function.php
form-process.php --> /functions/form-process.php
我打开了 php.ini 的输出缓冲
注意:这篇文章在回答后编辑
这是我的登录页面:
<?php
require("./functions/include-function.php");
?>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="./style/form.css">
<script type="text/javascript"src="./js/form.js">
</script>
<title></title>
</head>
<body>
<div class="wrapper">
<div class="container">
<h1>Welcome</h1>
<form class="form" method="get" action="./functions/form-process.php">
<input type="text" placeholder="Username" name="username">
<input type="text" placeholder="Username" name="username" value="<?php print_r($_COOKIE); ?>">
<input type="password" placeholder="Password" name="password">
<button type="submit" id="login-button" name="submit" value="submit">Login</button>
</form>
</div>
<ul class="bg-bubbles">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
</body>
</html>
这是我的流程页面:
<?php require("./include-function.php"); ?>
<?php
if (isset($_GET['submit'])) {
$username = $_GET['username'];
$pass = $_GET['password'];
$message = validation_form($_GET);
$value = 45;
$cookieName = "us";
if ($username == "vahid@gmail.com" && $pass == "123456" && empty($message)) {
$expired = time() + (60 * 60 * 24 * 1);
setcookie($cookieName,$value,$expired);
// redirect_to("http://www.youtube.com/");
print_r($_COOKIE);
}else{
redirect_to("../index.php");
}
}
?>
这是我的函数文件:
<?php
function redirect_to($location){
header("Location:". $location);
exit;
}
function validation_form($value=[]){
$message = [];
// Field must not Empty
// trim() so empty space not count
$username =trim($value['username']);
$password =trim($value['password']);
if (!isset($username) || $username==="" || empty($username)
|| !isset($password) || $password==="" || empty($password)) {
$message['validation'].="Username and Password must not empty";
}
// Length Check
$max = 20;
$min = 3;
if (strlen($username) > $max || strlen($password) > $max) {
$message['validation'].= "Password Or Username Must not more than 20 character";
}
if (strlen($username) < $min || strlen($password) < $min) {
$message['validation'].= "Password Or Username Must not less than 3 character";
}
// Type Check
if (!is_string($password)) {
$message['validation'].= "Password Must be Number";
}
//Preg_match
if (!preg_match("/@/",$username)) {
$message['validation'].= "Your username is your email ";
}
return $message;
}
?>