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 tag.
Syntax
setcookie(name, value, expire, path, domain);
See examples below
<?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>