Operation of PHP cookie implementation code of login

  • 2020-03-31 21:22:50
  • OfStack

The first file is login_frm.php and this is the login window
code
 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html;charset=utf8" /> 
</head> 
<body> 
<form method="post" action="login.php"> 
 The user :<input type="text" name="username" /> 
<input type="submit" value=" submit " /> 
</form> 
</body> 
</html> 

The second file login.php is the one that handles the login
 
<?php 
if($_POST['username'] = 'admin') 
{ 
setcookie('haha','gogo'); 
header("location:index.php"); 
} 
?> 

The third file, index.php, takes a look again
 
<?php 
if($_COOKIE['haha'] == 'gogogo') 
{ 
echo $_COOKIE['haha']; 
echo' You set the cookie'; 
} 
else 
{ 
echo' You didn't set it cookie'; 
} 
?> 

More basic can be referred to (link: #)

Related articles: