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

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

PHP中文网
Release: 2016-05-25 17:16:00
Original
2772 people have browsed it

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>
Copy after login

                   

                   

Related labels:
php
Statement of this Website
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
Latest Articles by Author
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template