亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Home php教程 php手冊(cè) 一個(gè)別致的計(jì)數(shù)器

一個(gè)別致的計(jì)數(shù)器

Jun 21, 2016 am 09:14 AM
counter img quot

計(jì)數(shù)器

如果你是網(wǎng)蟲,或僅僅是一位網(wǎng)絡(luò)編程的愛好者,你肯定曾經(jīng)擁有過個(gè)人主頁。或者充分發(fā)揮你的才華,制作出別具一格、讓人耳目清爽的網(wǎng)頁;或者收集了全天下的精品素材、教程、應(yīng)用軟件,完成了你的網(wǎng)絡(luò)教室、天下軟件大寶庫的專業(yè)網(wǎng)站。也許你也曾經(jīng)不非吹灰之力就申請(qǐng)到一個(gè)實(shí)用的計(jì)數(shù)器,發(fā)布到你自己的網(wǎng)站上,對(duì)自己的網(wǎng)站的訪問流量一清二楚;也許你曾經(jīng)花費(fèi)了九牛二虎之力編寫自己的網(wǎng)站計(jì)數(shù)器,隨心所欲的編輯計(jì)數(shù)器的各項(xiàng)功能,不斷的完成你想盡心統(tǒng)計(jì)的項(xiàng)目。但是,無論如何,擁有酷的計(jì)數(shù)器,就是一種享受、一種前所沒有的滿足。
(--以上內(nèi)容僅代表用戶的個(gè)人意見,并不代表本網(wǎng)站的立場(chǎng)--某某網(wǎng)站。:-D)

現(xiàn)在,普遍流行的計(jì)數(shù)器無非都是用CGI、ASP、PHP等篇寫的一個(gè)統(tǒng)計(jì)網(wǎng)頁被訪問的次數(shù)服務(wù)器端運(yùn)行程序。主要有包含在程序或者HTML代碼中的內(nèi)嵌的程序代碼,或者引入到網(wǎng)頁中的程序。本文介紹的就是用一個(gè)單獨(dú)的程序生成一個(gè)gif圖像,并且被包含到我們的主頁中來(http://www.21php.com)。

本計(jì)數(shù)器的原理非常簡(jiǎn)單,只要懂一點(diǎn)C語言或者其他程序語言,就能完全看懂每一行程序代碼;本程序?qū)⒂脩粼L問某個(gè)頁面的數(shù)據(jù)按24小時(shí)分組,然后按照不同時(shí)段保存成一個(gè)數(shù)組(用逗號(hào)“,”分割),每當(dāng)用戶訪問了該網(wǎng)頁,當(dāng)前時(shí)段的數(shù)據(jù)增加1,保存文件,并且按比例輸出直方圖;如果各位讀者有興趣,也可以參照原型不斷的開發(fā)更加好用的網(wǎng)站計(jì)數(shù)器。
本計(jì)數(shù)器有兩個(gè)要點(diǎn):一是讀取文件的數(shù)據(jù)。二是根據(jù)一定的算法將不同時(shí)段的訪問量按照一定的比例做成圖像,然后輸出到瀏覽器上,進(jìn)行顯示。
以下是本計(jì)數(shù)器的源代碼及作者波波的一些粗劣的講解。


############################################################
#***** Counters *****#
#***** Writed by Boban *****#
#***** Program at 2000年11月23日 *****#
############################################################
//提交圖片文件信息頭
Header("Content-type:image/gif");
####
//宏定義,預(yù)先定義好打印文字的左邊距ML的值為10
//可以自己根據(jù)調(diào)試的要求進(jìn)行題調(diào)整。
define("ML",10); //left margin

$imgh=30;
$imgw=300;
$Visited=array();

//如果文件Counter不存在的話,則創(chuàng)建一個(gè)這個(gè)文件
if (!file_exists("Counter"))
{
for($i=0;$i$Visited[$i]=0;
$str=$Visited[0];
for($i=1;$i$str.=",$Visited[$i]";
//格式化數(shù)據(jù),然后寫入文件之中
$fp=fopen("Counter","w");
fputs($fp,$str);
fclose($fp);
}
else
{
//讀出計(jì)數(shù)器的值
$fp=fopen("Counter","r");
$str=trim(fgets($fp,100));
$Visited=explode(",",$str);
//將數(shù)據(jù)轉(zhuǎn)化成數(shù)組的格式輸出
fclose($fp);
}

$Visited[date("G")]=intval($Visited[date("G")])+1;
//當(dāng)前時(shí)間的訪問量增加1
$max=intval($Visited[0]);
$str=$Visited[0];
for($i=1;$i{
$str.=",$Visited[$i]";
if($max$max=intval($Visited[$i]);
}
//找出最大的訪問量
$fp=fopen("Counter","w");
fputs($fp,$str);
fclose($fp);

$img=imagecreate($imgw+1,$imgh*2+1);
$bgcolor=imagecolorallocate($img,255,255,255);
$textcolor=imagecolorallocate($img,255,0,0);
$linecolor=imagecolorallocate($img,99,99,99);

imagerectangle($img,0,0,$imgw,$imgh*2,$linecolor);
$sum=0;
for($i=0;$i{
imagefilledrectangle($img,ML+$i*12,$imgh-$Visited[$i]*25/$max,ML+$i*12+4,$imgh,$linecolor);
imagestring($img,1,ML+$i*12,$imgh+4,$i,$textcolor);
$sum+=$Visited[$i];
}
//以上是按比例輸出直方圖

imagestring($img,3,10,$imgh+15,"Total:$sum",$textcolor);
imagestring($img,3,$imgw/3,$imgh+15,"Design by 21PHP Work Studio",$textcolor);

imagegif($img);
imagedestroy($img);
//生成圖像,清除內(nèi)存
?
以上程序是在PHP+Apache的環(huán)境下運(yùn)行的,使用時(shí)尚需注意以下事項(xiàng):
1.程序運(yùn)行的權(quán)限,請(qǐng)注意你的網(wǎng)頁能否運(yùn)行PHP程序。
2.文件讀寫的權(quán)限,因?yàn)槌绦蜻\(yùn)行過程中要進(jìn)行程序的讀寫。而且一般情況下,Apache的運(yùn)行權(quán)限是nobody,也就是說,只有最低的權(quán)限,所以最好新開一個(gè)目錄,將它的權(quán)限設(shè)定為nobody,計(jì)數(shù)器的程序也放在這個(gè)目錄里面。
以上程序的效果,可以到我的網(wǎng)站(http://www.21php.com)上看,如果需要源代碼的,也可以到我們的網(wǎng)站下載源代碼。文章也非常歡迎各大站點(diǎn)轉(zhuǎn)載,只要注明“作者Boban及轉(zhuǎn)自http://www.21php.com”即可。
Boban 2000年12月1日0:18分



Statement of this Website
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

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1488
72
How to open img file How to open img file Sep 18, 2023 am 09:40 AM

Methods to open img files include using virtual optical drive software, using compression software, and using special tools. Detailed introduction: 1. Use virtual optical drive software to open, download and install a virtual optical drive software, right-click the img file, select "Open with" or "Associated Program", select the installed virtual optical drive software in the pop-up dialog box, virtual The optical drive software will automatically load the img file and use it as a disc image in the virtual optical drive. Double-click the disc icon in the virtual optical drive to open the img file and access its contents, etc.

How to open img file How to open img file Jul 06, 2023 pm 04:17 PM

How to open the img file: 1. Confirm the img file path; 2. Use the img file opener; 3. Select the opening method; 4. View the picture; 5. Save the picture. The img file is a commonly used image file format, usually used to store picture data.

What is the format of img? What is the format of img? Mar 17, 2023 am 10:33 AM

img is a file compression format, mainly used to create image files of floppy disks. It can be used to compress the contents of an entire floppy disk or an entire CD; files with the extension ".IMG" are created using this file format. ; The img file includes 3 basic nodes, namely "Ehfa_HeaderTag", "Ehfa_File" and "Ehfa_Entry".

php提交表單通過后,彈出的對(duì)話框怎樣在當(dāng)前頁彈出,該如何解決 php提交表單通過后,彈出的對(duì)話框怎樣在當(dāng)前頁彈出,該如何解決 Jun 13, 2016 am 10:23 AM

php提交表單通過后,彈出的對(duì)話框怎樣在當(dāng)前頁彈出php提交表單通過后,彈出的對(duì)話框怎樣在當(dāng)前頁彈出而不是在空白頁彈出?想實(shí)現(xiàn)這樣的效果:而不是空白頁彈出:------解決方案--------------------如果你的驗(yàn)證用PHP在后端,那么就用Ajax;僅供參考:HTML code

U disk pe cannot read img U disk pe cannot read img Mar 19, 2024 pm 12:07 PM

U disk is one of the frequently used storage devices. There will also be some minor problems during use. For example: the U disk cannot be read. How to solve it? Put it away! Can’t read the USB flash drive? 4 steps to teach you how to solve the problem easily. After the USB flash drive has been inserted into the computer, click the Start menu, select Control Panel and put it away! Can’t read the USB flash drive? 4 steps to teach you to easily solve the problem. Find and double-click Device Manager in Control Panel. Keep it! Can’t read the USB flash drive? 4 steps to teach you how to easily solve the problem: Find the Universal Serial Bus controller on the main interface of the Device Manager and put it away! Can’t read the USB flash drive? 4 steps to teach you how to easily find the USB mass storage device, select it, right-click, find Uninstall and put it away! Can’t read the USB flash drive? 4 steps to teach you how to solve the problem easily. Welcome to leave a message for discussion!

How to change the src attribute of img in jquery How to change the src attribute of img in jquery Mar 03, 2022 pm 03:41 PM

How to change the img src attribute in jquery: 1. Use the attr() attribute, the syntax "$("img").attr("src","The address of the image file")"; 2. Use the prop() method, the syntax " $("img").prop("src","The address of the image file")".

How to use the Counter module in Python How to use the Counter module in Python Apr 19, 2023 pm 02:55 PM

Description Project Description Python Interpreter 3.10.6 Counter module In Python's collections module, a very commonly used module is Counter. Counter is a simple counter used to count the number of certain hashable objects. It stores elements and their counts in the form of a dictionary. Counter() class Counter() can count the parameters passed to this class according to certain rules, and return the results in the form of a dictionary by using the counting object and the counting result as key-value pairs. Counter(iterable=None,/,**kwds) gives an example fromcollectionsimport

what does image tag mean in html what does image tag mean in html Mar 04, 2021 pm 02:37 PM

In HTML, the image tag refers to the tag used to define the image, that is, the "<img>" tag. The img element can embed an image into a web page. The "<img>" tag is used to create a placeholder for the referenced image and link the image to the HTML page; the img tag uses the src attribute to specify the URL for displaying the image. Syntax "<img src="imageurl">".

See all articles