PHP/SQL 单页浏览量计数器

发布于 2024-10-14 13:13:17 字数 429 浏览 0 评论 0原文

嘿伙计们,我几个小时以来一直在寻找一个好的答案,但找不到我要找的东西!

如果我有一个动态网站(也许是新闻),我会得到以下链接

../domain.com/?newsid=1

../domain.com/?newsid=2

../domain.com/?newsid=3 等..

现在我将为每个页面都有一个单独的计数器..

因此,我会检查每个访问者,如果有人阅读“新闻 1”20 次,那么它也应该只算 1 次。 =>也许使用 IP 或 Cookie。

它应该是一个我可以包含在 php 代码中的函数,例如

我从来没有想过这样的事情。希望有人可以帮助我并给我一些提示如何编写这样的脚本(我是 php 新手顺便说一句)

Hey guys, I was looking for a good answer some hours now but can't find what I'm looking for!

If I have a dynamic Website (maybe news) I got the following links

../domain.com/?newsid=1

../domain.com/?newsid=2

../domain.com/?newsid=3 etc..

now I would have a individual counter for each of this page..

So I would check every single visitor and if someone is reading the "news 1" 20 times it also should count only 1 time. => Maybe with IP or Cookie.

It should be a function that I can include into the php code like <? pageviews(ID)?>

I never thougth anything like this. Hope someone can help me and give me some tips how I can code a script like this (I'm php newbie btw)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小…红帽 2024-10-21 13:13:17

您应该考虑在新闻表中使用计数器字段,例如,当有人打开 ?newsid=1 时,您可以执行以下操作:

$newsid = intval($_GET['newsid']);
mysql_query("UPDATE news set counter=counter+1 WHERE id=$newsid");

You should consider using a counter field in your news table such that when someone opens ?newsid=1 for example, you do this:

$newsid = intval($_GET['newsid']);
mysql_query("UPDATE news set counter=counter+1 WHERE id=$newsid");
暗藏城府 2024-10-21 13:13:17

我在 http:// /talkerscode.com/webtricks/create-a-simple-pageviews-counter-using-php-and-mysql.php 让我简短地创建一个包含行数和页面的表,然后编写此代码

$user_ip=$_SERVER['REMOTE_ADDR'];

$check_ip = mysql_query("select userip from pageview where page='yourpage' and userip='$user_ip'");
if(mysql_num_rows($check_ip)>=1)
{

}
else
{
  $insertview = mysql_query("insert into pageview values('','yourpage','$user_ip')");

    $updateview = mysql_query("update totalview set totalvisit = totalvisit+1 where page='yourpage' ");
}

i found a great article on http://talkerscode.com/webtricks/create-a-simple-pageviews-counter-using-php-and-mysql.php let me short the code create a table with rows count and page and then write this code

$user_ip=$_SERVER['REMOTE_ADDR'];

$check_ip = mysql_query("select userip from pageview where page='yourpage' and userip='$user_ip'");
if(mysql_num_rows($check_ip)>=1)
{

}
else
{
  $insertview = mysql_query("insert into pageview values('','yourpage','$user_ip')");

    $updateview = mysql_query("update totalview set totalvisit = totalvisit+1 where page='yourpage' ");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文