Add a cookie for each article in the user's representative has been viewed. is that reasonable?

Source: Internet
Author: User
Add a cookie on the user's behalf for each article that has been viewed. Is it reasonable?
Recently, one of the functions of the fuss is to count the number of views (traffic) of the current article


My article address is news.php?id=123.

Find a way online

$gid = $_get["id";






if ($_cookie["user"]! = "Oldguest") {
$hits _now = $row ["hits"]+1;
$pdo->exec ("UPDATE ' Gamedb_game ' SET ' hits ' = ' $hits _now ' WHERE ' id ' = ' $gid '");
}



In this case, the same browser will refresh the second time, will not repeat the increase in the number of views

But I think not, go to other articles, even if the first time to browse, do not increase the view

What do I think?


$gid = $_get["id";






if ($_cookie["user"]! = "Oldguest_$gid") {
$hits _now = $row ["hits"]+1;
$pdo->exec ("UPDATE ' Gamedb_game ' SET ' hits ' = ' $hits _now ' WHERE ' id ' = ' $gid '");
}


change the oldguest to Oldguest_$gid there is an article ID added to the back, there is a uniqueness of it?

but does this, to some extent, have a bad response to the user's browser?

Or does the other CMS do it?

If you want to write SQL to match whether it's the first time, it's too complicated.

Think of only cookies


This way to my own host, as well as to the user, what will happen?
------Solution--------------------
View count increase refresh once more no problem yes,
If you really want to use your method do not let it see it can be put into the cache, set a time to draw, specify the time to take one, many sites are doing so.
Your method can try to put the article ID into the array, and then sequence the words, save the cookie to try.
------Solution--------------------
Record the title of the article viewed by the user to a cookie, and the next time the user opens the page to view the article, there will be a record that was last viewed.
This is a bit like you do shopping site browsing products, the next time you go to see, there is your last browsing record.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.