php graphics display Ip address code and comments

  • 2020-12-18 01:46:29
  • OfStack

Use graphics to display Ip, file sunip.php


<?php 
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']; 
} // www.ofstack.com
$col = imagecolorallocate($im, 0, 51, 102); 
imagestring($im, 3, 5, 1, $ip , $col); 
imagegif($im); 
imagedestroy($im); 
?>

1. < ?php

2. header("Content-type: image/gif");
Line 2 declares the browser header output as GIF graphics
3. $im = imagecreate(130,15);
Create a figure imagecreate(130,15). 130,15 in brackets represent width and height respectively
4. $background_color = ImageColorAllocate ($im, 255, 255, 255);
Set the Background Color imagecolorallocate Assigns a color to 1 image ($im, 255, 255, 255)im represents the three 255 after the new image mentioned earlier and 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'];
}
If $_SERVER['HTTP_CLIENT_IP'] is available, use $_SERVER['HTTP_CLIENT_IP'] to determine if this section is compatible with multiple server Settings
7. $col = imagecolorallocate($im, 0, 51, 102);
Define text color
8. imagestring($im, 3, 5, 1, $ip , $col);
Paint the obtained IP onto the new canvas imagestring($im, 3, 5, 1, $ip, $col); Represents imagestring(graphic representation, character size 1-5,X coordinates,Y coordinates, output IP, color)
9. imagegif($im);
Output GIF graphics
10. imagedestroy($im);
Free memory
11. ? >
End of the program


Related articles: