A Web page can show "File upload Time" and "number of visitors", not only the history of the article record, but also reflects the popularity of the article's audience. "File Upload Time" and "number of visitors" record method must be many, the author according to their own understanding with Php+mysql wrote a, I do not know the code is not enough to optimize, but it feels good to use, no problem, write to share with everyone.
Ideas
1, the article upload first in the database to write "Web address", "Upload Time ()" and "Count start 0".
2, when users open the Web page, first through the $_session["article"] to determine whether online. If not, open the database, remove the original count, add 1, and then update the database. Prevent online users from "refreshing", virtual increment count.
3, open and remove the last updated count, displayed on the Web page.
Example
Write it in front of
The code is as follows |
Copy Code |
<?php Session_Start (); $stsfile = "10001.php"; $nowtime = time (); Date_default_timezone_set ("asia/chongqing")/Set time standard if (!isset ($_session[' article ')) | | $_session[' article ']!= $stsfile)//Determine if the user is online { $link = mysql_connect ("localhost", "Library name", "password") or Die ("Open database Failed"); mysql_select_db ("library name", $link); Connecting to a database mysql_query ("Set names ' UTF8 '"); Set access encoding Query $stsfile whether the record already exists, if it does not exist insert time and count cardinality 0, if present, then +1, update count. $sql = "SELECT * from Statistics WHERE ' stsfile ' = ' $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 [' Stsnumb ']+1; mysql_query ("UPDATE" Statistics ' SET ' stsnumb ' = ' $numb ' WHERE ' stsfile ' = ' $stsfile '); Session_Start (); $_session[' article ' = $stsfile; Write down $_session[] } } ?> |
The page Display section is the
code is as follows |
copy code |
<?php $link = mysql_connect ("localhost", "Library name", "password") or Die ("Open database Failed"); mysql_select_db ("library name", $link);//Connection Database mysql_query ("Set names ' UTF8");//Set access encoding $sql = "SELECT * FROM Statisti CS WHERE ' stsfile ' = ' $stsfile '; $result =mysql_query ($sql); $row = mysql_fetch_array ($result); Echo Upload time:. Date ("Y-m-d h:i:s", $row [' Ststime ']). "Browse Number:". $row [' Stsnumb ']; ?> |