Php + mysql article browsing count statistics and release time _ PHP Tutorial

Source: Internet
Author: User
Statistics on the browsing times and release time of php + mysql articles. This article will introduce you to a php + mysql article browsing times Statistics and release time instance. if you need this, please refer to it. This article will introduce you to a php + mysql article browser count and release time instance when a file is uploaded on a Web page. if you need this, go to the reference page.

A web page displays the "File upload time" and "browsing users", which not only records the history of the article, but also reflects the audience popularity of the article. There are certainly many ways to record "file upload time" and "browser count". I wrote one in php + mysql based on my own understanding. I don't know if the code is not optimized enough, but it feels good to use it, no problem. I will share it with you today.

Ideas

1. when uploading an article, write "webpage address", "upload time ()", and "Count start point 0" in the database ".

2. when a user opens a webpage, the user first checks whether the webpage is online through $ _ SESSION ["article. If it is not online, open the database, retrieve the original count, add 1, and then update the database. Prevents online users from "refreshing" and increasing the count falsely.

3. Open and retrieve the last updated count and display it on the webpage.

Example

InWrite down:

The code is as follows:

Session_start ();
$ Stsfile = "10001.php ";
$ Nowtime = time ();
Date_default_timezone_set ("Asia/Chongqing"); // sets the time standard.
If (! Isset ($ _ SESSION ['article']) | $ _ SESSION ['article']! = $ Stsfile) // determines whether the user is online.
{
$ Link = mysql_connect ("localhost", "database name", "password") or die ("failed to open database ");
Mysql_select_db ("database name", $ link); // connect to the database
Mysql_query ("set names 'utf8'"); // sets the access encoding.

// Query whether the $ stsfile record already exists. if the record does not exist, the insert time and count base number are 0. if the record exists, + 1 is used to update the count.
$ SQL = "SELECT * FROM statistics WHERE 'sfile' = '$ stsfile '";
$ Result = mysql_query ($ SQL );
$ Row = mysql_fetch_array ($ result );
If (empty ($ row ['stsid'])
{



Mysql_query ("insert into 'Statistics '('stsfile', 'ststime', 'stsnumb') VALUES (' $ stsfile', '$ nowtime', '0 ')");
Session_start ();
$ _ SESSION ['article'] = $ stsfile;
}
Else
{
$ Numb = $ row ['snumb'] + 1;
Mysql_query ("UPDATE 'Statistics 'set' stsnumb' = '$ numb' WHERE 'stsfile' =' $ stsfile '");
Session_start ();
$ _ SESSION ['article'] = $ stsfile; // write down $ _ SESSION []
}
}
?>

The page display area isLater part:

The code is as follows:

$ Link = mysql_connect ("localhost", "database name", "password") or die ("failed to open database ");
Mysql_select_db ("database name", $ link); // connect to the database
Mysql_query ("set names 'utf8'"); // sets the access encoding.
$ SQL = "SELECT * FROM statistics WHERE 'sfile' = '$ stsfile '";
$ Result = mysql_query ($ SQL );
$ Row = mysql_fetch_array ($ result );
Echo "upload time :". date ("Y-m-d H: I: s", $ row ['stime']). "Browsing quantity :". $ row ['snumb'];

?>

Bytes. A web page displays the file uploaded...

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.