Home > Backend Development > PHP Tutorial > php cookie logout settings output and logout study notes

php cookie logout settings output and logout study notes

PHP中文网
Release: 2023-02-28 19:02:01
Original
1356 people have browsed it

This is a study note from a friend when he was learning PHP. Its function is to set a cookie and then log out and output the cookie value.

The setcookie() function is used to set cookies.

Note: The setcookie() function must be placed before the tag.

Syntax

setcookie(name, value, expire, path, domain);
Copy after login

See examples below

<?php
//注销cookie
if(isset($_GET[&#39;out&#39;])){
setcookie(&#39;us&#39;,"");
echo "<script>location.href=&#39;index.php&#39;</script>"; 
}

//设置cookie
if(isset($_POST[&#39;sub&#39;])){
setcookie("us",$_POST[&#39;user&#39;],time()+3600);
echo "<script>location.href=&#39;index.php&#39;</script>";
}

//输出和注销cookie
if($_COOKIE[&#39;us&#39;]){
echo $_COOKIE[&#39;us&#39;];
echo "<a href=&#39;index.php?out=out&#39;>注销cookies</a>"; 
}

?>
<form method="post">
<input type="text" name="user">
<input type="password" name="pass">
<input type="submit" name="sub" value="提交">
</form>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template