3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

そのページの(自分の)訪問回数をカウントする関数

3
Last updated at Posted at 2014-08-07

この関数を呼ぶ度にクッキーでcountをインクリメントしていく関数

用法:
 引数にそのページのid(string)を与えてあげる。
 ex)get_countVisits('page274')
効能:
 初めて来たかそうでないかを判断したいときなどに効く。


function get_countVisits($strId)
{
	$life = 60 * 60 * 24 * 30 * 12;//* 約1年 本当はこうすべき:60 * 60 * 24 * 365
	if(isset($_COOKIE["count".$strId])) {
		$count = $_COOKIE["count".$strId] + 1;
	}
	else {
		$count = 1;
	}
	setcookie("count".$strId, $count, time() + $life);
	return $count;
}
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?