Home  >  Article  >  php教程  >  PHP 使用 Cookie 记录用户访问某页面的次数

PHP 使用 Cookie 记录用户访问某页面的次数

PHP中文网
PHP中文网Original
2016-05-25 17:16:002708browse

php代码   

<?php
if (!isset($_COOKIE[&#39;visits&#39;])) $_COOKIE[&#39;visits&#39;] = 0;
$visits = $_COOKIE[&#39;visits&#39;] + 1;
setcookie(&#39;visits&#39;,$visits,time()+3600*24*365);
?>
<html>
<head>
<title> Title </title>
</head>
<body>
<?php
if ($visits > 1) {
  echo("This is visit number $visits.");
} else { // First visit
  echo(&#39;Welcome to oschina.net! Click here for a tour!&#39;);
}
?>
</body>
</html>

                   

                   

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn