ASP text article click Statistics Code

Source: Internet
Author: User

Class Views {
Private $update _time = 1800; Update, Unit seconds
Private $log _dir = './www.111cn.net/log/'; File storage Directory
Private $pid = ' 0 '; Article ID
function __construct ($po _id) {
$pid = (is_numeric ($po _id) && $po _id > 0)?                Intval ($po _id): 0; Get article ID
$this->pid = $pid;
}
Read the document and click the number + 1
function Read () {
if ($this->pid > 0) {
$s = "";
$filename = Site_root $this->log_dir. ' Click_log.txt '; Filename
if (file_exists ($filename)) {
$content = file_get_contents ($filename);
if ($content) {
$dary = Explode ("", $content); Array the contents of the document
foreach ($dary as $line) {
$data _ary = explode (' | ', $line);
$ary [$data _ary[0]] = $data _ary[1];
}
}
if (array_key_exists ($this->pid, $ary)) {//check key exists in the array
$ary [$this->pid] = $ary [$this->pid] + 1; Add the number of clicks to the current article by 1
} else {
$ary [$this->pid] = 1; Article ID appears for the first time so give an initial value of 1
}
foreach ($ary as $key => $val) {
$s. = $key. ' | '. $val. "                "; Array complete and revert to document format
}
Print_r ($s);
} else {
$s. = $this->pid. ' | 1 '. '                        "; This is the initialization document Www.111cn.net
}
}
$fp = fopen ($filename, "w");
if (Flock ($FP, LOCK_EX)) {//Exclusive lock
Fwrite ($fp, $s);
Flock ($FP, lock_un); Release lock
}
Fclose ($FP);
@chmod ($filename, 0777);
}
}
$a = new Views ("3");
$a->read ();

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.