Heim  >  Artikel  >  Backend-Entwicklung  >  php cookie注销 设置 输出和注销学习笔记

php cookie注销 设置 输出和注销学习笔记

PHP中文网
PHP中文网Original
2017-03-13 15:32:161288Durchsuche

这是一个朋友在学php时的一个学习笔记,其功能就是设置cookie然后注销及输出cookie值的具体操作方法。

setcookie() 函数用于设置 cookie。

注释:setcookie() 函数必须位于 100db36a723c770d327fc0aef2ce13b1 标签之前。

语法

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

下面看实例

<?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>
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn