关于在 PHP 中创建简单页面计数器的两部分问题
1) 如何向 PHP 页面添加简单的页面计数器并将值插入 MySQL 表中?另外,我需要在每次新访问时更新 MySQL 表值。
2) 窍门在于,PHP 页面是各种用户生成的登陆页面的模板。例如,我希望每个页面都有自己单独的计数器:
examplesite.com/template.php?getvalue=bob
examplesite.com/template.php?getvalue=sam
examplesite.com/template.php?getvalue=samantha
我的印象是,如果我将计数器放在“template.php”文件中,那么它将把每个用户的所有访问量累加起来。我想要的输出是让每个用户只获得单个登陆页面的计数。
因此,如果总共有 12 次访问,分布如下:
examplesite.com/template.php?getvalue=bob had 4 visits
examplesite.com/template.php?getvalue=sam had 2 visits
examplesite.com/template.php?getvalue=samantha had 6 visits
那么我希望 bob 的页计数器读为“4”,sam 的读为“2”,samantha 的读为“6”。我是否正确地假设,如果我将计数器放在 template.php 上,每个用户的登陆页面都会读取为“12”?您有解决此问题的简单方法吗?
1) How do I add a simple page counter to a PHP page and insert the values in a MySQL table? Also I would need the MySQL table value to be updated with each new visit.
2) The trick is that the PHP page is a template for a variety of user generated landing pages. For example, I would like each of these pages to have their own separate counters:
examplesite.com/template.php?getvalue=bob
examplesite.com/template.php?getvalue=sam
examplesite.com/template.php?getvalue=samantha
My impression is that if I put the counter on the "template.php" file then it will add up all the visits from each user to a grand total. The output that I would like is to have each user only get counts for the individual landing page.
So, if there are a total of 12 visits, dispersed as follows:
examplesite.com/template.php?getvalue=bob had 4 visits
examplesite.com/template.php?getvalue=sam had 2 visits
examplesite.com/template.php?getvalue=samantha had 6 visits
then I would want bob's page counter to read as '4', sam's as '2' and samantha's as '6.' Am I correct in assuming that if I just put the counter on template.php that each user's landing page would read as '12?' Do you have a solution for an easy way to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这很简单:
That's pretty simple:
好吧,正如您可以在生成页面时分离对 bob 和 sam 的请求一样,您可以对计数器执行相同的操作吗?
您可能会使用
$_GET['getvalue']
执行某些操作。只需在查询中使用该值(转义的、参数化的等)来更新您的计数器...然后绑定 getvalue...
Well, just as you are able to separate the requests for bob and sam when generating the page, you can do the same for the counter?
You'll probably do something with
$_GET['getvalue']
. Just use that value (escaped, paramterized etc) in a query to update your counter....and then bind the getvalue...
您希望在 MySQL 表中为每个用户保留一行。当您要更新表时,通过读取 getvalue 来更新该用户的相应行。然后执行相同的操作来显示用户的页面计数器。
You would want to have a row in your MySQL table for each user. When you go to update the table, update the appropriate row for that user by reading the getvalue. Then do the same for displaying the user's page counter.