PHP 로그인 암호 기억하기

form 페이지
 
<form action="login.php" method="post">
<input type="text" name="username"><br>
<input type="text" name="password"><br>
<input type="checkbox" name="jizhu" value="1"><br>
<input type="submit">
</form>
<a href="userinfo.php"> </a>
<?php
session_start();
function p($arr){
echo "<pre>";
print_r($arr);
echo "</pre>";
}
p($_SESSION);
p($_COOKIE);
?>
페이지에 로그인합니다
 
<?php
function p($arr){
echo "<pre>";
print_r($arr);
echo "</pre>";
}
session_start();
//p($_POST);
$_SESSION['username'] = $_POST['username'];
$_SESSION['password'] = $_POST['password'];
if($_POST['jizhu']){
setcookie('username',$_POST['username'],time()+60);
setcookie('password',$_POST['password'],time()+60);
}
header("location:form.php");
사용자 정보 페이지
 
<?php
session_start();
echo " , form.php , ";
p($_SESSION);
p($_COOKIE);
if(empty($_SESSION['username'])){
if(empty($_COOKIE['username'])){
echo "<a href='form.php'> </a>";exit;
}else{
$_SESSION['username'] = $_COOKIE['username'];
}
}
function p($arr){
echo "<pre>";
print_r($arr);
echo "</pre>";
}
?>
2131231231
<a href="updateuserinfo.php"> </a>
<a href="logout.php"> </a>
페이지 출시
 
<?php
session_start();
unset($_SESSION['username']);
unset($_SESSION['password']);
setcookie('username','',0);
setcookie('password','',0);
header("location:form.php");
?>
사용자 정보 페이지를 수정합니다
 
<?php
session_start();
if(empty($_SESSION['username'])){
echo " ";
}else{
echo " ";
}
?>

좋은 웹페이지 즐겨찾기