First look at the code
sunip.php
Copy the code The code is as follows:
header( "Content-type: image/gif");
$im = imagecreate(130,15);
$background_color = ImageColorAllocate ($im, 255, 255, 255);
unset($ip) ;
if($_SERVER['HTTP_CLIENT_IP']){
$ip=$_SERVER['HTTP_CLIENT_IP'];
} else if($_SERVER['HTTP_X_FORWARDED_FOR']){
$ip =$_SERVER['HTTP_X_FORWARDED_FOR'];
} else{
$ip=$_SERVER['REMOTE_ADDR'];
}
$col = imagecolorallocate($im, 0, 51, 102) ;
imagestring($im, 3, 5, 1, $ip, $col);
imagegif($im);
imagedestroy($im);
?>
I will explain it step by step below
I am not an expert and figured it out
1. 2. header("Content-type: image/gif");
The second line declares the browser header and outputs it as a GIF graphic
3. $im = imagecreate(130,15);
Create a graphic imagecreate(130,15) 130 and 15 in brackets represent the width and Height
4. $background_color = ImageColorAllocate ($im, 255, 255, 255);
Set the background color imagecolorallocate to assign a color to a picture ($im, 255, 255, 255)im represents the previously mentioned The three 255s after the new graphic represent the decimal characters of the color table ffffff
5. unset($ip);
useless
6.if($_SERVER['HTTP_CLIENT_IP']){
$ip=$_SERVER['HTTP_CLIENT_IP'];
} else if($_SERVER['HTTP_X_FORWARDED_FOR']){
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
} else{
$ip=$_SERVER['REMOTE_ADDR'];
}
If $_SERVER['HTTP_CLIENT_IP'] can be used, use $_SERVER['HTTP_CLIENT_IP'] similar to the following. For judgment, this paragraph is to be compatible with multiple servers Set
7. $col = imagecolorallocate($im, 0, 51, 102);
Define text color
8. imagestring($im, 3, 5, 1, $ip, $col);
Draw the obtained IP onto the new canvas imagestring($im, 3, 5, 1, $ip, $col); respectively represent imagestring (graphical representation, character size 1-5, X coordinate, Y coordinate) , output IP, color)
9. imagegif($im);
Output GIF graphics
10. imagedestroy($im);
Release memory
11. ?>
End of program
http://www.bkjia.com/PHPjc/318397.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/318397.htmlTechArticleLook at the code sunip.php first. Copy the code as follows: ?php header("Content-type:image/gif" ); $im=imagecreate(130,15); $background_color=ImageColorAllocate($im,255,255,255); unset($ip);...