主页
PHP
PHP Cookie
demo_cookie3
运行 ❯
×
更改方向
保存代码
更改主题
<?php $cookie_name = "user"; $cookie_value = "Alex Porter"; setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); ?> <?php if(!isset($_COOKIE[$cookie_name])) { echo "Cookie named '" . $cookie_name . "' is not set!"; } else { echo "Cookie '" . $cookie_name . "' is set!
"; echo "Value is: " . $_COOKIE[$cookie_name]; } ?>
Note:
You might have to reload the page to see the new value of the cookie.
Cookie 'user' is set!
Value is: John Doe
Note:
You might have to reload the page to see the new value of the cookie.