PHP中動態(tài)顯示簽名和ip原理
更新時(shí)間:2007年03月28日 00:00:00 作者:
<?php
//包含一個(gè)計(jì)數(shù)器,一個(gè)提醒語句,用戶ip以及自己的廣告圖片。
//給瀏覽器發(fā)送頭,說我是張圖片
Header("Content-type: image/PNG");
//這里定義計(jì)數(shù)器,放到一個(gè)文件里的
$Visited=array();
if (!file_exists("Counter"))
{
for($i=0;$i<24;$i++)
$Visited[$i]=0;
$str=$Visited[0];
for($i=1;$i<24;$i++)
$str.=",$Visited[$i]";
$fp=fopen("Counter","w");
fputs($fp,$str);
fclose($fp);
}
else
{
$fp=fopen("Counter","r");
$str=trim(fgets($fp,100));
$Visited=explode(",",$str);
fclose($fp);
}
$Visited[date("G")]=intval($Visited[date("G")])+1;
$str=$Visited[0];
$max=intval($Visited[0]);
for($i=1;$i<24;$i++)
{
$str.=",$Visited[$i]";
if($max<=intval($Visited[$i]))
$max=intval($Visited[$i]);
}
$fp=fopen("Counter","w");
fputs($fp,$str);
fclose($fp);
$sum=0;
for($i=0;$i<24;$i++)
{
$sum+=$Visited[$i];
}
//計(jì)數(shù)器結(jié)束
//開始創(chuàng)建圖片定義顏色字體等
$im = imagecreate(400,100);
$black = ImageColorAllocate($im, 0,0,0);
$white = ImageColorAllocate($im, 255,255,255);
$red = ImageColorAllocate($im, 255,0,0);
$blue = ImageColorAllocate($im, 0,0,255);
$font=5;
$maginx=20;
$maginy=20;
//定義ip和主機(jī)名,當(dāng)然是用戶端的
$ip = getenv('REMOTE_ADDR');
$host = gethostbyaddr($ip);
$today = getdate();
$wday = $today['wday'];
//提醒片斷,是周末則好不是周末則提醒上課
if($wday==6 || $wday==0){
$tips = "enjoy the wonderful weekend!";
}else{
$tips = "you'd better go to school.";
}
if($wday ==1){
$wday = "Monday";
} elseif ($wday==2){
$wday="Tuesday";
} elseif ($wday==3){
$wday="Wednsday";
} elseif ($wday==4){
$wday="Thursday";
} elseif ($wday==5){
$wday="Friday";
} elseif ($wday==6){
$wday="Saturday";
} elseif ($wday==0){
$wday="Sunday";
}
//開始創(chuàng)建圖像背景邊框
imagefill($im,0,0,$black);
imagefilledrectangle ($im, 1, 1, 398, 98, $white);
//定義畫筆
$style = array ($white,$white,$white,$white,$white,$white,$white,$white,$white,$red);
imagesetstyle ($im, $style);
//有個(gè)運(yùn)動效果就用筆刷來刷了,相當(dāng)于photoshop中的畫筆工具也
//ads是我自己的廣告圖
$brush = imagecreatefrompng ("http://172.24.16.80/testpic/smile1.png");
$brush1 = imagecreatefrompng ("http://172.24.16.80/testpic/ads.png");
$w2 = imagecolorallocate($brush,255,255,255);
imagecolortransparent ($brush, $w2);
imagesetbrush ($im, $brush);
imageline ($im, 350,20,360,20, IMG_COLOR_STYLEDBRUSHED);
imagecopy ($im, $brush1, 270, 40, 0, 0, 119, 48);
//定義輸出文字
imagestring($im,$font,$maginx,$maginy+20,"Your computer's named:{$host}",$red);
imagestring($im,$font,$maginx,$maginy,"Your IP Address is:{$ip}",$red);
imagestring($im,2,2,2,"Today is {$wday} and {$tips}",$blue);
imagestring($im,3,10,$maginy+40,"TotalRefreshTimesFromToday:$sum",$blue);
//圖片結(jié)尾必然語句
ImagePNG($im);
ImageDestroy($im);
?>
//包含一個(gè)計(jì)數(shù)器,一個(gè)提醒語句,用戶ip以及自己的廣告圖片。
//給瀏覽器發(fā)送頭,說我是張圖片
Header("Content-type: image/PNG");
//這里定義計(jì)數(shù)器,放到一個(gè)文件里的
$Visited=array();
if (!file_exists("Counter"))
{
for($i=0;$i<24;$i++)
$Visited[$i]=0;
$str=$Visited[0];
for($i=1;$i<24;$i++)
$str.=",$Visited[$i]";
$fp=fopen("Counter","w");
fputs($fp,$str);
fclose($fp);
}
else
{
$fp=fopen("Counter","r");
$str=trim(fgets($fp,100));
$Visited=explode(",",$str);
fclose($fp);
}
$Visited[date("G")]=intval($Visited[date("G")])+1;
$str=$Visited[0];
$max=intval($Visited[0]);
for($i=1;$i<24;$i++)
{
$str.=",$Visited[$i]";
if($max<=intval($Visited[$i]))
$max=intval($Visited[$i]);
}
$fp=fopen("Counter","w");
fputs($fp,$str);
fclose($fp);
$sum=0;
for($i=0;$i<24;$i++)
{
$sum+=$Visited[$i];
}
//計(jì)數(shù)器結(jié)束
//開始創(chuàng)建圖片定義顏色字體等
$im = imagecreate(400,100);
$black = ImageColorAllocate($im, 0,0,0);
$white = ImageColorAllocate($im, 255,255,255);
$red = ImageColorAllocate($im, 255,0,0);
$blue = ImageColorAllocate($im, 0,0,255);
$font=5;
$maginx=20;
$maginy=20;
//定義ip和主機(jī)名,當(dāng)然是用戶端的
$ip = getenv('REMOTE_ADDR');
$host = gethostbyaddr($ip);
$today = getdate();
$wday = $today['wday'];
//提醒片斷,是周末則好不是周末則提醒上課
if($wday==6 || $wday==0){
$tips = "enjoy the wonderful weekend!";
}else{
$tips = "you'd better go to school.";
}
if($wday ==1){
$wday = "Monday";
} elseif ($wday==2){
$wday="Tuesday";
} elseif ($wday==3){
$wday="Wednsday";
} elseif ($wday==4){
$wday="Thursday";
} elseif ($wday==5){
$wday="Friday";
} elseif ($wday==6){
$wday="Saturday";
} elseif ($wday==0){
$wday="Sunday";
}
//開始創(chuàng)建圖像背景邊框
imagefill($im,0,0,$black);
imagefilledrectangle ($im, 1, 1, 398, 98, $white);
//定義畫筆
$style = array ($white,$white,$white,$white,$white,$white,$white,$white,$white,$red);
imagesetstyle ($im, $style);
//有個(gè)運(yùn)動效果就用筆刷來刷了,相當(dāng)于photoshop中的畫筆工具也
//ads是我自己的廣告圖
$brush = imagecreatefrompng ("http://172.24.16.80/testpic/smile1.png");
$brush1 = imagecreatefrompng ("http://172.24.16.80/testpic/ads.png");
$w2 = imagecolorallocate($brush,255,255,255);
imagecolortransparent ($brush, $w2);
imagesetbrush ($im, $brush);
imageline ($im, 350,20,360,20, IMG_COLOR_STYLEDBRUSHED);
imagecopy ($im, $brush1, 270, 40, 0, 0, 119, 48);
//定義輸出文字
imagestring($im,$font,$maginx,$maginy+20,"Your computer's named:{$host}",$red);
imagestring($im,$font,$maginx,$maginy,"Your IP Address is:{$ip}",$red);
imagestring($im,2,2,2,"Today is {$wday} and {$tips}",$blue);
imagestring($im,3,10,$maginy+40,"TotalRefreshTimesFromToday:$sum",$blue);
//圖片結(jié)尾必然語句
ImagePNG($im);
ImageDestroy($im);
?>
相關(guān)文章
啟用Csrf后POST數(shù)據(jù)時(shí)出現(xiàn)的400錯(cuò)誤
這篇文章主要介紹了啟用Csrf后POST數(shù)據(jù)時(shí)出現(xiàn)的400錯(cuò)誤的相關(guān)資料,需要的朋友可以參考下2015-07-07ie與session丟失(新窗口cookie丟失)實(shí)測及解決方案
正如標(biāo)題所言測試結(jié)果為:如果cookie設(shè)置是延后定時(shí)失效,而非進(jìn)程級的,那在open后也能看到,所以,針對此情況,防止用戶在使用ie內(nèi)核出現(xiàn)登錄狀態(tài)丟失,可以配合cookie來使用2013-07-07

PHP實(shí)現(xiàn)批量檢測網(wǎng)站是否能夠正常打開的方法
這篇文章主要介紹了PHP實(shí)現(xiàn)批量檢測網(wǎng)站是否能夠正常打開的方法,涉及php使用自定義函數(shù)及curl操作的相關(guān)技巧,需要的朋友可以參考下
2016-08-08 
php簡單實(shí)現(xiàn)查詢數(shù)據(jù)庫返回json數(shù)據(jù)
這篇文章主要介紹了php簡單實(shí)現(xiàn)查詢數(shù)據(jù)庫返回json數(shù)據(jù),并附上2則示例代碼,非常的簡單實(shí)用,有需要的小伙伴可以參考下。
2015-04-04 
通過緩存數(shù)據(jù)庫結(jié)果提高PHP性能的原理介紹
眾所周知,緩存數(shù)據(jù)庫查詢的結(jié)果可以顯著縮短腳本執(zhí)行時(shí)間,并最大限度地減少數(shù)據(jù)庫服務(wù)器上的負(fù)載。如果要處理的數(shù)據(jù)基本上是靜態(tài)的,則該技術(shù)將非常有效。這是因?yàn)閷h(yuǎn)程數(shù)據(jù)庫的許多數(shù)據(jù)請求最終可以從本地緩存得到滿足,從而不必連接到數(shù)據(jù)庫、執(zhí)行查詢以及獲取結(jié)果
2012-09-09 
PHP實(shí)現(xiàn)通過文本文件統(tǒng)計(jì)頁面訪問量功能示例
這篇文章主要介紹了PHP實(shí)現(xiàn)通過文本文件統(tǒng)計(jì)頁面訪問量功能,涉及php文件讀寫、數(shù)值計(jì)算及圖形操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下
2019-02-02