Heojju

[PHP] cookie - 쿠키 사용법 본문

웹개발/PHP

[PHP] cookie - 쿠키 사용법

우주별 2017. 8. 23. 18:07

▤ create

<?php
$cookie_name = "name";
$cookie_value = "heojju";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1일
?>


▤ retrieve

<?php
echo $_COOKIE[$cookie_name];
?>

결과 : heojju


▤ modify

<?php
$cookie_name = "name";
$cookie_value = "woojoo";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1일
?>


▤ delete

<?php
setcookie("name", "", time() - 3600);
?>


▤ enable check

<?php
if(count($_COOIE)>0){echo "exist";}else{echo "null";}
?>