First look Code
Sunip. php
Copy code The Code is as follows: <? PHP
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 '];
}
$ Col = imagecolorallocate ($ im, 0, 51,102 );
Imagestring ($ im, 3, 5, 1, $ IP, $ col );
Imagegif ($ IM );
Imagedestroy ($ IM );
?>
Next I will explain it one by one
I am not an expert at all.
1. <? PHP
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 End