当前位置:Gxlcms > PHP教程 > phpcookie注销设置输出和注销学习笔记

phpcookie注销设置输出和注销学习笔记

时间:2021-07-01 10:21:17 帮助过:24人阅读

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

setcookie() 函数用于设置 cookie。

注释:setcookie() 函数必须位于 <html> 标签之前。

语法

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

下面看实例

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

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

//
输出和注销cookie if($_COOKIE['us']){ echo $_COOKIE['us']; echo "<a href='index.php?out=out'>注销cookies</a>"; } ?> <form method="post"> <input type="text" name="user"> <input type="password" name="pass"> <input type="submit" name="sub" value="提交"> </form>

人气教程排行