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

php cookie logout settings output and logout study notes

PHP中文网
PHP中文网Original
2017-03-13 15:32:161287browse

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 100db36a723c770d327fc0aef2ce13b1 tag.

Syntax

setcookie(name, value, expire, path, domain);

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>
Statement:
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