开发者

Logic behind counting the views of a page

开发者 https://www.devze.com 2023-01-28 06:25 出处:网络
I m trying to created a code for the page in which no. of views are needed to be shown in the bottom of the page.

I m trying to created a code for the page in which no. of views are needed to be shown in the bottom of the page.

I don't know what will be the logic behind counting the views. let's say the vie开发者_运维问答ws like on the home page of the stackoverflow. I like they way they display. And the logic for the same. (it'll be done via the php-mysql)

Please help Thanks in advance


Set a function to select if their IP address is already in the table where you track your hits, if it is don't add one to the count, otherwise add 1 to the count as well as their IP for future tracking.


You'd stick something like this in the header of each page:

<?php
    updatePageHitCount('name of page here');
?>

where the 'name of page here' is some unique identifier for the page. The function would then basically just do some SQL:

UPDATE pagehitcounts
SET hitcount = hitcount + 1
WHERE pageID = 'name of page here';

Of course, you'd want something a little more robust, but this would be the basics.

0

精彩评论

暂无评论...
验证码 换一张
取 消