PHP code for displaying IP addresses in a graphic _ PHP Tutorial

Source: Internet
Author: User
A graph displays the PHP code of the IP address. Let's first read the code sunip. php and copy the code as follows :? Phpheader (Content-type: imagegif); $ imimagecreate (255,255,255); $ background_colorImageColorAllocate ($ im,); unset ($ ip); read the code first
Sunip. php

The code is as follows:


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. 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 ended

The sunip. php code is as follows :? Php header ("Content-type: image/gif"); $ im = imagecreate (255,255,255); $ background_color = ImageColorAllocate ($ im ); unset ($ ip );...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.