This article describes how to use php to display Ip addresses in graphics. If you need it, you can refer to the graphic display Ip address and file sunip. php.
The Code is as follows:
Header ("Content-type: image/gif ");
$ Im = imagecreate (130,15 );
$ Background_color = ImageColorAllocate ($ instant, 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 '];
} // Www.php.net
$ Col = imagecolorallocate ($ im, 0, 51,102 );
Imagestring ($ im, 3, 5, 1, $ ip, $ col );
Imagegif ($ im );
Imagedestroy ($ im );
?>
1.
2. header ("Content-type: image/gif ");
The second line declares that the browser header is output as a GIF image.
3. $ im = imagecreate (130,15 );
Create an image imagecreate () with and 15 representing the width and height respectively.
4. $ background_color = ImageColorAllocate ($ im, 255,255,255 );
Set the background color imagecolorallocate to assign a color ($ im, 255,255,255) to an image. im stands for the three 255 s after the new image mentioned above, and represents the 10-digit character of the ffffff color table.
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'] to determine whether this segment is compatible with multiple SERVER settings.
7. $ col = imagecolorallocate ($ im, 0, 51,102 );
Define text color
8. imagestring ($ im, 3, 5, 1, $ ip, $ col );
Draw the obtained IP address to the newly created canvas imagestring ($ im, 3, 5, 1, $ ip, $ col), representing imagestring (graphical representation, character size: 1-5, X, Y, output IP, color)
9. imagegif ($ im );
Output GIF Image
10. imagedestroy ($ im );
Release memory
11.?>
Program ended