본문 바로가기

프로그래밍

쿠키 생성, 사용, 삭제

<?php 
$a = setcookie("userid", "rubato");
$b = setcookie("username", "kim", time()+60);

if ($a and $b)
{
echo "쿠키 'userid'와 'username' 생성 완료<br>";
echo "쿠키 'username'은 60초(1분) 간 지속됨";
}
?>

<?php 
if (isset($_COOKIE["userid"]) && isset($_COOKIE["username"]))
{
$userid = $_COOKIE["userid"];
$username = $_COOKIE["username"];

echo "userid 쿠키 : " . $userid."<br>";
echo "username 쿠키 : " .$username."<br>";
}
else
{
echo "쿠키가 생성되지 않았습니다.";
}
?>

<?php 
setcookie("uerid", "", time() -3600);
setcookie("uername", "", time() -3600);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
</head>
<body>
<?php 
{
echo "userid 와 username 쿠키가 삭제되었습니다.";
}
?>
</body>
</html>

'프로그래밍' 카테고리의 다른 글

아이디 비번 입력  (0) 2022.03.06
게시판2  (0) 2022.03.06
게시판  (0) 2022.03.06
조건문2(학점출력)  (0) 2022.01.08
조건문1  (0) 2022.01.08