+ -
当前位置:首页 → 问答吧 → 利用代码为网页加IP地址转换功能

利用代码为网页加IP地址转换功能

时间:2007-04-19

来源:互联网

这两天有空写了个给网页自由加入IP地址的功能
复制PHP内容到剪贴板
PHP代码:

<?php
/***************************************************************
hiler制作
Mail:[email protected]
使用说明:
一,传递IP数据至本页面,本站示例为通过表单提交.
二,一般的网页访问者IP地址可以通过PHP内置函数 例:$ip = getenv('remote_addr');获得;
三,把程序中变量$ip_addr插入到网页中合适的位置;
欢迎改进和更新;
WE中国[webedit.cn]出品
2007-4-19 ShenYang
***************************************************************/
 $ip = $_POST['url_add'];//转换通过表单提交的IP
 if($ip =='')
 {
  $ip = getenv('remote_addr');//转换访问本页的用户IP
 }
  $buffer = file_get_contents ("[url=http://www.ip.cn/ip.php?q=$ip]http://www.ip.cn/ip.php?q=$ip[/url]", "r");
  $str_pos = strpos($buffer,'纯真版');
  $str_pos2 = strpos($buffer,'心语星空');
  $ip_addr = substr($buffer,$str_pos,($str_pos2-$str_pos));
  $str_pos4 = strpos($ip_addr,"<font color=red>");
  $str_pos5 = strpos($ip_addr,"</font><br>");
  //$ip_addr = $ip.":".substr($ip_addr,($str_pos4+16),($str_pos5-$str_pos4-16));//显原IP地址
  $ip_addr = substr($ip_addr,($str_pos4+16),($str_pos5-$str_pos4-16));//不显原IP地址
?>
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml' lang='zh-CN'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=gb2312' />
<title>IP地址所属地转换器----网页嵌入版</title>
</head><?=$ip_addr?><!-- 以下部分为测试用-->
<form method='post' action='ip.php'>
<input type='text' name='url_add'><br>
<input type='submit'value='偷IP地址数据'>
</form>
<!-- 以上部分为测试用-->
</html>

作者: hiler   发布时间: 2007-04-19