这是一个朋友在学php时的一个学习笔记,其功能就是设置cookie然后注销及输出cookie值的具体操作方法。
setcookie() 函数用于设置 cookie。
注释:setcookie() 函数必须位于 标签之前。
语法
setcookie(name, value, expire, path, domain);
下面看实例
立即学习“PHP免费学习笔记(深入)”;
<?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>











