时间:2021-07-01 10:21:17 帮助过:24人阅读
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>