Home > Article > Backend Development > Code and comments for php to realize graphic display of IP address_PHP tutorial
Use graphic display of IP, file sunip.php
1.
2. header("Content-type: image/gif");
The second line declares that the browser header output is a GIF graphic
3. $im = imagecreate(130,15);
Create a graphic imagecreate(130,15) 130,15 in brackets represent the width and height respectively
4. $background_color = ImageColorAllocate ($im, 255, 255, 255);
Set the background color imagecolorallocate to a picture Image allocation color ($im, 255, 255, 255) im represents the three 255s after the new graphic mentioned above, which represents 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'];
}
Use if $_SERVER['HTTP_CLIENT_IP'] is available $_SERVER['HTTP_CLIENT_IP'] The following is similar to determine whether this paragraph is to be compatible with various server settings
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 graphic
10. imagedestroy( $im);
Release memory
11. ?>
Program ends