PHP中动态显示签名和ip原理
程序员文章站
2022-04-08 23:53:33
<?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);
?>
//包含一个计数器,一个提醒语句,用户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);
?>
上一篇: JAVA 框架之面向对象设计原则
下一篇: 白酒是下层喝的“臭酒”