Home > Backend Development > PHP Tutorial > Principle of dynamically displaying signature and IP in PHP_PHP tutorial

Principle of dynamically displaying signature and IP in PHP_PHP tutorial

WBOY
Release: 2016-07-21 15:55:35
Original
952 people have browsed it

//Contains a counter, a reminder statement, user IP and its own advertising image.
//Send a header to the browser, saying I am a picture
Header("Content-type: image/PNG");
//Define the counter here and put it in a file
$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];
}
//End of counter
//Start creating image definition Color font, etc.
$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;
//Define the ip and host name, of course the client's
$ip = getenv('REMOTE_ADDR');
$host = gethostbyaddr($ip);
$today = getdate();
$wday = $today['wday'];
//Reminder fragment, it is better if it is the weekend, not the weekend to remind class
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";
}
//Start creating the image background border
imagefill($im,0,0,$black);
imagefilledrectangle ($im, 1, 1, 398, 98 , $white);
//Define brush
$style = array ($white,$white,$white,$white,$white,$white,$white,$white,$white,$red) ;
imagesetstyle ($im, $style);
//If there is a movement effect, I use a brush to brush it, which is equivalent to the brush tool in photoshop
//ads is my own advertising image
$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);

//Define the output text
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);

//Necessary statement at the end of the picture
ImagePNG($im);
ImageDestroy($im);
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/318244.htmlTechArticle?php //Contains a counter, a reminder statement, user IP and its own advertising image. //Send a header to the browser, saying I am a picture Header("Content-type:image/PNG"); //Definition here...
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template