Home > Backend Development > PHP Tutorial > A PHP program code that graphically displays IP_PHP Tutorial

A PHP program code that graphically displays IP_PHP Tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 15:55:04
Original
967 people have browsed it

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 step by step below
I am not an expert and figured it out
1. 2. header("Content-type: image/gif");
The second line declares the browser header and outputs it as a GIF graphic
3. $im = imagecreate(130,15);
Create a graphic imagecreate(130,15) 130 and 15 in brackets represent the width and Height
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 previously mentioned The three 255s after the new graphic represent 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'] can be used, use $_SERVER['HTTP_CLIENT_IP'] similar to the following. For judgment, this paragraph is to be compatible with multiple servers Set
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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/318397.htmlTechArticleLook at the code sunip.php first. Copy the code as follows: ?php header("Content-type:image/gif" ); $im=imagecreate(130,15); $background_color=ImageColorAllocate($im,255,255,255); unset($ip);...
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Why does it still jump after returning false?
From 1970-01-01 08:00:00
0
0
0
Optimize table indexes in MySQL
From 1970-01-01 08:00:00
0
0
0
Why can't I install it?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template