Code and comments for php to realize graphic display of IP address_PHP tutorial

WBOY
Release: 2016-07-13 10:40:38
Original
832 people have browsed it

Use graphic display of IP, file sunip.php

Copy 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'];
} // www.jbxue.com
$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 output is a GIF graphic
3. $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 a picture Image allocation color ($im, 255, 255, 255) im represents the three 255s after the new graphic mentioned above, which 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'];
}
Use if $_SERVER['HTTP_CLIENT_IP'] is available $_SERVER['HTTP_CLIENT_IP'] The following is similar to determine whether this paragraph 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 graphic
10. imagedestroy( $im);
Release memory
11. ?>
Program ends

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/718606.htmlTechArticleUse graphics to display IP, file sunip.php Copy the code as follows: ?php header("Content-type: image /gif"); $im = imagecreate(130,15); $background_color = ImageColorAllocate ($im, 2...
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!