0){. ..}" circularly compares the IPs stored in the data table. If the IP exists, it will not be recorded again."/> 0){. ..}" circularly compares the IPs stored in the data table. If the IP exists, it will not be recorded again.">

Home  >  Article  >  Backend Development  >  How to achieve single article view count in php

How to achieve single article view count in php

藏色散人
藏色散人Original
2022-11-18 09:45:151956browse

php method to implement single article browsing count: 1. Create a php sample file; 2. Obtain the IP through "$_SERVER['REMOTE_ADDR'];"; 3. Through "if(mysql_num_rows($query ) > 0){...}" circularly compares the IPs stored in the data table. If the IP exists, it will not be recorded again.

How to achieve single article view count in php

The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.

How to achieve single article view count in php?

PHP counts the number of visits to a single article

First add a field to record the number of visits to the data table that stores the corresponding article.

  • You can add one to the number of fields each time you access it, but this will be inaccurate because it will be recorded as long as it is refreshed.

  • In order to prevent the above situation from happening, you can record the IP address of the visitor. Repeated IP address visits will only be recorded once.

  • However, there are problems if an IP address is only recorded once. For example, if multiple visitors on a local area network share the same IP address, the records will be inaccurate. Therefore, it is best to record one visit to an IP address once within a certain period of time. This is relatively better.

  • However, even if the IP address is recorded, there may be malicious users who switch IPs or use ticket brushing software to increase the number of visits.

 0){
//IP存在
}else{
//记录访问量
}
?>

Note: If you want to use files without using a database, you can directly write a script on the server to count the access log

Recommended learning: "PHP Video Tutorial

The above is the detailed content of How to achieve single article view count in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn