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 one by one below Explain
What is going on? I am not an expert and I just figured it out
1. . $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 assign a color to a picture ($im, 255, 255, 255) im represents the new graphic mentioned above, and the next three 255 represent the decimal characters of the color table ffffff
5. unset($ip ; ['HTTP_X_FORWARDED_FOR'];
} else{
$ip=$_SERVER['REMOTE_ADDR'];
}
If $_SERVER['HTTP_CLIENT_IP'] can be used, use $_SERVER['HTTP_CLIENT_IP']. The following is similar to judge this paragraph It 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 graphics
10. imagedestroy($im);
Release memory
11. ?>
End of program
The above introduces a PHP program code that graphically displays IP, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.