Home > php教程 > php手册 > php实现图形显示Ip地址的代码及注释

php实现图形显示Ip地址的代码及注释

WBOY
Release: 2016-06-06 20:25:34
Original
1406 people have browsed it

这篇文章主要介绍了php实现图形显示Ip地址,有需要的朋友可以参考一下

使用图形显示Ip,,文件 sunip.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'];
} //
$col = imagecolorallocate($im, 0, 51, 102);
imagestring($im, 3, 5, 1, $ip , $col);
imagegif($im);
imagedestroy($im);
?>

1.

2. header("Content-type: image/gif");
第二行 声明浏览器标头 输出为GIF图形
3. $im = imagecreate(130,15);
建立一个图形 imagecreate(130,15)括号内130,15分别代表宽度和高度
4. $background_color = ImageColorAllocate ($im, 255, 255, 255);
设置背景颜色 imagecolorallocate 为一幅图片分配颜色 ($im, 255, 255, 255)im代表前面提到的新建图形 后面的3个255则代表颜色表ffffff的10进制字符
5. unset($ip);
无用
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'];
}
如果$_SERVER['HTTP_CLIENT_IP']可以使用则使用$_SERVER['HTTP_CLIENT_IP']下面类似 为判断 此段是为了兼容多种服务器设置
7. $col = imagecolorallocate($im, 0, 51, 102);
定义文字颜色
8. imagestring($im, 3, 5, 1, $ip , $col);
将获取到的IP画到新建的画布上 imagestring($im, 3, 5, 1, $ip , $col); 分别代表imagestring(图形表示,字符尺寸1-5,X坐标,Y坐标,输出的IP,颜色)
9. imagegif($im);
输出GIF图形
10. imagedestroy($im);
释放内存
11. ?>
程序结束

Related labels:
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template