PHP中動態顯示簽名和ip原理

來源:互聯網
上載者:User

<?php
//包含一個計數器,一個提醒語句,使用者ip以及自己的廣告圖片。
//給瀏覽器發送頭,說我是張圖片
Header("Content-type: image/PNG");
//這裡定義計數器,放到一個檔案裡的
$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];
}
//計數器結束
//開始建立圖片定義顏色字型等
$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和主機名稱,當然是使用者端的
$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";
}
//開始建立映像背景邊框
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);
//有個運動效果就用筆刷來刷了,相當於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);

//圖片結尾必然語句
ImagePNG($im);
ImageDestroy($im);
?>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.