页面访问计数代码

来源:互联网 发布:淘宝网购买南浔桔红糕 编辑:程序博客网 时间:2024/05/01 12:21

 

<?php
$shm_id = @shmop_open(0xff3, "w", 0644, 4);
if (!$shm_id)
{
echo "create counter!/n";
$shm_id = @shmop_open(0xff3, "c", 0644, 4);
if (!$shm_id)
{
echo "shmop_open error!/n";
exit;
}
}
$str_count = @shmop_read($shm_id, 0, 4);
if (!$str_count)
{
echo "shmop_read error!/n";
@shmop_close($shm_id);
exit;
}
$count = intval($str_count)+1;
if (!@shmop_write($shm_id, strval($count), 0))
{
echo "shmop_write error!";
@shmop_close($shm_id);
exit;
}
echo $count . " people viewed this page!/n";
@shmop_close($shm_id);
?>
///////////////////////////////////////
1、需要启用php_shmop模块
2、要更精确实用的话,需要结合数据库对历史记录,客户端ip、访问时间等进行综合考虑。

 

原创粉丝点击