|
显示IP的图片,其实并不是一张图片,你可以对着该图片点鼠标右键,然后选属性确认一下。
它们往往是:
http://*****.aspx?****或者
http://*****.php?****等形式
如果你懂网页设计的话,一看就明白怎么回事情了。也就是说其实我们看到的是一个网页。
我来举个例子:
我们先创建一个ip.php网页文件,其内容是:
<?php
Header(\"Content-type: image/PNG\");
$myip=$REMOTE_ADDR;
$im = imagecreate(158,35);
$bkg = ImageColorAllocate($im, 128,128,128 ); //背景色
$red = ImageColorAllocate($im, 204,204,204 ); //红色
$blue = ImageColorAllocate($im, 255,255,255 ); //蓝色
for ($i = 0; $i < strlen($myip); $i++) {
imagestring($im, 3, $i*10+5, 0, substr($myip,$i,1), $blue);//ImageColorAllocate($im,rand(5, 255),rand(5, 255),rand(5, 255))改成这样就成了随机色
}
imagestring($im,3,5,10,\"--------------------\",$red);
imagestring($im,3,20,20,\"Designed By Arcow\",$red);
ImagePNG($im);
ImageDestroy($im);
?>
然后将这个文件上传到一个支持php的服务器中,我们访问该文件,你看到的就是显示出你的IP地址的图片了。
好啦,那么我们该如何引用它呢?
我们再创建一个静态的网页文件如:test.htm
内容如下:
<html><head><title></title></head>
<body leftmargin=0 topmargin=0>
<img src=\"ip.php\" border=0>
</body></html>
如何取得用户的真实IP?
php代码:
<?
function iptype1 () {
if (getenv(\"HTTP_CLIENT_IP\")) {
return getenv(\"HTTP_CLIENT_IP\");
}
else {
return \"none\";
}
}
function iptype2 () {
if (getenv(\"HTTP_X_FORWARDED_FOR\")) {
return getenv(\"HTTP_X_FORWARDED_FOR\");
}
else {
return \"none\";
}
}
function iptype3 () {
if (getenv(\"REMOTE_ADDR\")) {
return getenv(\"REMOTE_ADDR\");
}
else {
return \"none\";
}
}
function ip() {
$ip1 = iptype1();
$ip2 = iptype2();
$ip3 = iptype3();
if (isset($ip1) && $ip1 != \"none\" && $ip1 != \"unknown\") {
return $ip1;
}
elseif (isset($ip2) && $ip2 != \"none\" && $ip2 != \"unknown\") {
return $ip2;
}
elseif (isset($ip3) && $ip3 != \"none\" && $ip3 != \"unknown\") {
return $ip3;
}
else {
return \"none\";
}
}
Echo ip();
?> |
|