php

一个PHP数据采集类

<?
// 兼容 php4 php5
// 程序作者  张建 52linux.com(我爱Linux)
// 联系方法  733905@qq.com  QQ 733905
// 简单调用方法
/*
<?
include ("ugs.php"); // 你可以下载本ugs.phps 然后重命名为ugs.php
$ugs = new ugs();
$url = "http://domainname.com/path_to_your_target?param";
$ugs->seturl($url);
$ugs->gather();
//............这里可以调用本类里的其它方法,对$ugs->value_  做调整,
以满足您的要求
$content=$ugs->getcontent();
print($content);
?>
*/
class ugs
{
var $value_  ;  //'目标内容
var $src_    ;  //'目标URL地址

function seturl($url)
{
$this->src_=$url;
}
function getcontent()
{
return $this->value_;
}
function getfile($url)
// 获取目标
{
$url_parsed = parse_url($url);
$host = $url_parsed["host"];
$port = $url_parsed["port"];
if ($port==0)  $port = 80;
$path = $url_parsed["path"];
if (empty($path))
$path="/";
if ($url_parsed["query"] != "")
$path .= "?".$url_parsed["query"
];
$out = "GET $path HTTP/1.0\r\nHost: $host\r\n\r\n"[font=新宋体];
$fp = fsockopen($host, $port, $errno, $errstr, 30);
fwrite($fp, $out);
$body = false;
while (!feof($fp))
{
$s = fgets($fp, 1024);
if ( $body )  $in .= $s;
if ( $s == "\r\n" )
$body = true;
}
fclose($fp);
return $in;
}

function getfile_curl($url)
{
$curl="/usr/local/bin/curl " ; // path to your curl
$curl_options=" -s --connect-timeout 10  --max-time 10  ";
// curl 用法请参考 curl --help 或者 man curl
// curl 参数非常之丰富,可以模拟各种浏览器(agent) 可以设置referer
$cmd="$curl $curl_options $url ";
@exec($cmd,$o,$r);
if($r!=0)
{
return "超时";
}
else
{
[color=#000000] $o=join("",$o);
return $o;
}
}

function gather_curl($curl)
{
$http=$this->getfile_curl($this->src_);
return $this->value_=$http;
}

function gather_array($url)
{
return file($url);
}

function  gather()
// 开始收集
{
$http=$this->getfile($this->src_);
return $this->value_=$http;
}

function gather_local($toline=true)
// 处理本地文件
{

if($toline)
{
$http=file($this->src_);
return $this->value_=$this->BytesToBstr($http);
}
else
{
$http=file($this->src_);
return
$this->value_=$http[font=新宋体];
}

}

function noReturn()
// 删除回车换行
{
$this->value_=str_replace("\n","",$this->value_);
$this->value_=str_replace("\r","",$this->value_);
}

function change($oldStr,$str)
//'对收集到的内容中的个别字符串用新值更换/方法
//'参数分别是旧字符串,新字符串
{
$this->value_=str_replace($oldStr,$str,$this->value_ );
}

function cut($start,$end,$no='1',$comprise='')
//'按指定首尾字符串对收集的内容进行裁减(不包括首尾字符串)方法
// $no 必须是 1,2 3 ... 不允许是0
//$comprise 可以选择 start 或者 end 或者 all 或者 什么都不填
{
$string=explode($start,$this->value_);
//print_r($string);
&n
bsp;  $string=explode($end,$string[$no]);
//print_r($string);
switch ($comprise
){
case 'start':
$string=$start.$string[0];
break;
case 'end':
$string=$string[0].$end;
break;
case 'all':
$string=$start.$string[0].$end;
break;
default:
$string=$string[0];
}
return $this->value_=$string;
}

function  filt($head,$bot,$str,$no='1',$comprise='')
//'按指定首尾字符串对收集的内容用新值进行替换(不包括首尾字符串)方法
// '参数分别是首字符串,尾字符串,新值,新值位空则为过滤
{
$tmp_v=$this->value_;
$tmp=$this->cut($head,$bot,$no,$comprise);
return $this->value_=str_replace[/font][/color][/font]
($tmp,$str,$tmp_v);
}

function  local()
{
//'将收集的内容中的绝对URL地址改为本地相对地址
// 还没实现
}

function  replaceByReg($patrn,$str)
//'对收集的内容中的符合正则表达式的字符串用新值进行替换/方法
//'参数是你自定义的正则表达式,新值
{
return $this->value_=join("",preg_replace($patrn,$str,$this->value_));
}

function debug()
//调试显示
{
$tempstr="<SCRIPT>function runEx(){var winEx2 = window.open(\"\", \"winEx2\", \"width=500,height=300,status=yes,menubar=no,scrollbars=yes,resizable=yes\"); winEx2.document.open(\"text/html\", \"replace\"); winEx2.document.write(unescape(event.srcElement.parentElement.children[0].value)); winEx2.document.close(); }function saveFile(){var win=window.open('','','top=10000,left=10000');win.document.write(document.all.asdf.innerText);win.document.execCommand('SaveAs','','javascript.htm');win.close();}</SCRIPT><center><TEXTAREA id=asdf name=textfield rows=32  wrap=VIRTUAL cols=\"120\">".$this->value_."</TEXTAREA><BR><BR><INPUT name=Button onclick=runEx() type=button value=\"查看效果\">  <INPUT name=Button onclick=asdf.select() type=button value=\"全选\">  <INPUT name=Button onclick=\"asdf.value=''\" type=button value=\"清空\">  <INPUT onclick=saveFile(); type=button value=\"保存代码\"></center>";
echo $tempstr;
}

}
?>

Popularity: 74%

php

给图片加水印类

set_time_limit(3000);
class GDMark {
var $sourcePath; //图片存储路径
var $galleryPath; //图片缩略图存储路径
var $toFile = false; //是否生成文件
var $WaterPos;
var $MarkSign = null;
var $fontName; //使用的TTF字体名称
var $maxWidth = 600; //图片最大宽度
var $maxHeight = 700; //图片最大高度

function GDMark($sourcePath, $galleryPath, $WaterPos, $fontPath, $MarkSign=”) {
$this->sourcePath = $sourcePath;
$this->galleryPath = $galleryPath;
$this->WaterPos=$WaterPos;
$this->fontName = $fontPath . “allegro0.TTF”;
$this->MarkSign = $MarkSign;
}

function waterMark($sourFile, $text=’Mark’) {
$imageInfo = $this->getInfo($sourFile);
$sourFile = $this->sourcePath . $sourFile;
$newName = substr($imageInfo["name"], 0, strrpos($imageInfo["name"], “.”)) . “_mark.jpg”;
switch ($imageInfo["type"]) {
case 1: $img = imagecreatefromgif($sourFile); break;
case 2: $img = imagecreatefromjpeg($sourFile); break;
case 3: $img = imagecreatefrompng($sourFile); break;
default: return 0; break;
}
if (!$img) return 0;
$width = ($this->maxWidth > $imageInfo["width"]) ? $imageInfo["width"] : $this->maxWidth;
$height = ($this->maxHeight > $imageInfo["height"]) ? $imageInfo["height"] : $this->maxHeight;
$srcW = $imageInfo["width"];
$srcH = $imageInfo["height"];
if ($srcW * $width > $srcH * $height) $height = round($srcH * $width / $srcW);
else $width = round($srcW * $height / $srcH);
if (function_exists(“imagecreatetruecolor”)) {
$new = imagecreatetruecolor($width, $height);
ImageCopyResampled($new, $img, 0, 0, 0, 0, $width, $height, $imageInfo["width"], $imageInfo["height"]);
} else {
$new = imagecreate($width, $height);
ImageCopyResized($new, $img, 0, 0, 0, 0, $width, $height, $imageInfo["width"], $imageInfo["height"]);
}
$white = imageColorAllocate($new, 255, 255, 255);
$black = imageColorAllocate($new, 0, 0, 0);
$red = imageColorAllocate($new, 255, 0, 0);
$gray = imageColorAllocate($new, 161, 161, 161);

if($this->MarkSign<>”){
$MarkInfo = $this->getInfo($this->MarkSign);
$widthm = $MarkInfo["width"];
$heightm = $MarkInfo["height"];
switch ($MarkInfo["type"]) {
case 1: $mark = imagecreatefromgif($this->MarkSign); break;
case 2: $mark = imagecreatefromjpeg($this->MarkSign); break;
case 3: $mark = imagecreatefrompng($this->MarkSign); break;
default: return 0; break;
}
$w = $widthm;
$h = $heightm;
}else{
$fontsize = $width>300?20:10;
$temp = imagettfbbox($fontsize, 0, $this->fontName, $text);
$w = $temp[2] – $temp[6];
$h = $temp[3] – $temp[7];
unset($temp);
}

switch($this->WaterPos) {
case 0://随机
$posX = rand(0,($width – $w));
$posY = rand($h,($height – $h));
break;
case 1://1为顶端居左
$posX = 0;
$posY = 0;
break;
case 2://2为顶端居中
$posX = ($width – $w) / 2;
$posY = 0;
break;
case 3://3为顶端居右
$posX = $width – $w;
$posY = $h;
break;
case 4://4为中部居左
$posX = 0;
$posY = ($height – $h) / 2;
break;
case 5://5为中部居中
$posX = ($width – $w) / 2;
$posY = ($height – $h) / 2;
break;
case 6://6为中部居右
$posX = $width – $w;
$posY = ($height – $h) / 2;
break;
case 7://7为底端居左
$posX = 0;
$posY = $height – $h;
break;
case 8://8为底端居中
$posX = ($width – $w) / 2;
$posY = $height – $h;
break;
case 9://9为底端居右
$posX = $width – $w-5;
$posY = $height – $h-5;
break;
default://随机
$posX = rand(0, ($width – $w));
$posY = rand($h, ($height – $h));
break;
}

if($this->MarkSign<>”){
imagecopy($new, $mark, $posX, $posY, 0, 0, $widthm, $heightm);
imagedestroy($mark);
}else{
$alpha = imageColorAllocateAlpha($new, 200, 200, 200, 70);
ImageFilledRectangle($new, 0, $posY-$h, $width, $posY+5, $alpha);
// ImageFilledRectangle($new, 13, $height-20, 15, $height-7, $black);
ImageTTFText($new, $fontsize, 0, $posX, $posY, $black, $this->fontName, $text);
}
if ($this->toFile) {
if (file_exists($this->galleryPath . $newName)) unlink($this->galleryPath . $newName);
ImageJPEG($new, $this->galleryPath . $newName);
return $this->galleryPath . $newName;
} else {
ImageJPEG($new,$sourFile);
}
ImageDestroy($new);
ImageDestroy($img);
}

function getInfo($file) {
$file = $this->sourcePath . $file;
$data = getimagesize($file);
$imageInfo["width"] = $data[0];
$imageInfo["height"]= $data[1];
$imageInfo["type"] = $data[2];
$imageInfo["name"] = basename($file);
return $imageInfo;
}

}

$mark=new GDMark(”, ”, 9, ”, ‘./watermark.png’);

$mark->waterMark(“2.jpg”);

echo ““;

?>

Popularity: 6%

javascript

实现一个年、月、季度联动SELECT的javascript代码

<body>
<table border=0 height=30px >
<tr>
<td width=80px>
<select onchange="displaySubmenu(this.value)">
<option value="none">请选择报告类型</option>
<option value="1,4">月度报告</option>
<option value="1,3">季度报告</option>
<option value="1,2">半年报告</option>
<option value="1">年度报告</option>
</select>
</td>
<td>
<select id="submenu_1" name="year" style="display:none;"></select>
</td>
<td>
<select id="submenu_2" name="semiyear" style="display:none;"></select>

<select id="submenu_3" name="quarter" style="display:none;"></select>

<select id="submenu_4" name="month" style="display:none;"></select>
</td>
<td>
<input id="ok" type="button" onClick='GetValue();' value="取值">
</td>
</tr>

</table>

<script>
function GetValue(){
var objlist = document.getElementsByTagName("SELECT");
var tmp = new Array();
var tap = objlist[0].options[objlist[0].selectedIndex].text;
strTmp="";
var j = 1;
for(var i=1;i<objlist.length;i++){
if(objlist[i].style.display!="none"){
strTmp += objlist[i].options[objlist[i].selectedIndex].text + "-";
j++;
}
}
strTmp = strTmp.substring(0,strTmp.length-1);
alert(tap);
alert(strTmp);

}

function hideAll(){
for(i=1;i<5;i++){
var select = document.getElementById("submenu_"+i);
while(select.options.length>0){
select.options.remove(0);
}
select.style.display = "none";
}
}

function initSelect(index){
var select = document.getElementById("submenu_"+index);
var now = new Date();
var currentYear = now.getYear();
var month = now.getMonth();
switch(index){
case 1:
for(i=-5;i<=5;i++){
var value = currentYear+i;
var item = new Option(value,value);
select.options.add(item);
}
select.selectedIndex = 5;
select.style.display = "block";
break;
case 2:
var semiyears = new Array("上半年","下半年");
for(i=0;i<2;i++){
var item = new Option(semiyears[i],i+1);
select.add(item);
}
select.selectedIndex = Math.floor(month/6);
select.style.display = "block";
break;
case 3:
var quarters = new Array("一季度","二季度","三季度","四季度");
for(i=0;i<4;i++){
var item = new Option(quarters[i],i+1);
select.add(item);
}
select.selectedIndex = Math.floor(month/3);
select.style.display = "block";
break;
case 4:
var months = new Array("一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月");
for(i=0;i<12;i++){
var item = new Option(months[i],i+1);
select.add(item);
}
select.selectedIndex = month;
select.style.display = "block";
break;
default:
break;
}
}

function displaySubmenu(command){
hideAll();
if(command != "none"){
var commands = command.split(",");
for(l=0;l<commands.length;l++){
initSelect(parseInt(commands[l]));
}
}
}
</script>
</body>

Popularity: 10%

php

[GD]生成bmp格式的图片(imagebmp)

GD库里没有生成bmp图片的函数,所以自己写了一个,这个函数尚有一个压缩算法没有写,不过已经够用了。需要的同学可以看看。

int imagebmp ( resource image [, string filename [, int $bit [, int compression]]] )

$im: 图像资源
$filename: 如果要另存为文件,请指定文件名,为空则直接在浏览器输出
$bit: 图像质量(1、4、8、16、24、32位)
$compression: 压缩方式,0为不压缩,1使用RLE8压缩算法进行压缩

注意:这个函数仍然需要GD库的支持。

Demo:

$im = imagecreatefrompng(“test.png”);
imagebmp($im);
imagedestroy($im);
Source:

/**
* 创建bmp格式图片
*
* @author: legend(legendsky@hotmail.com)
* @link: http://www.ugia.cn/?p=96
* @description: create Bitmap-File with GD library
* @version: 0.1
*
* @param resource $im 图像资源
* @param string $filename 如果要另存为文件,请指定文件名,为空则直接在浏览器输出
* @param integer $bit 图像质量(1、4、8、16、24、32位)
* @param integer $compression 压缩方式,0为不压缩,1使用RLE8压缩算法进行压缩
*
* @return integer
*/
function imagebmp(&$im, $filename = ”, $bit = 8, $compression = 0)
{
if (!in_array($bit, array(1, 4, 8, 16, 24, 32)))
{
$bit = 8;
}
else if ($bit == 32) // todo:32 bit
{
$bit = 24;
}

$bits = pow(2, $bit);

// 调整调色板
imagetruecolortopalette($im, true, $bits);
$width = imagesx($im);
$height = imagesy($im);
$colors_num = imagecolorstotal($im);

if ($bit <= 8)
{
// 颜色索引
$rgb_quad = ”;
for ($i = 0; $i < $colors_num; $i ++)
{
$colors = imagecolorsforindex($im, $i);
$rgb_quad .= chr($colors['blue']) . chr($colors['green']) . chr($colors['red']) . “\0″;
}

// 位图数据
$bmp_data = ”;

// 非压缩
if ($compression == 0 || $bit < 8)
{
if (!in_array($bit, array(1, 4, 8)))
{
$bit = 8;
}

$compression = 0;

// 每行字节数必须为4的倍数,补齐。
$extra = ”;
$padding = 4 – ceil($width / (8 / $bit)) % 4;
if ($padding % 4 != 0)
{
$extra = str_repeat(“\0″, $padding);
}

for ($j = $height – 1; $j >= 0; $j –)
{
$i = 0;
while ($i < $width)
{
$bin = 0;
$limit = $width – $i < 8 / $bit ? (8 / $bit - $width + $i) * $bit : 0;

for ($k = 8 – $bit; $k >= $limit; $k -= $bit)
{
$index = imagecolorat($im, $i, $j);
$bin |= $index << $k;
$i ++;
}

$bmp_data .= chr($bin);
}

$bmp_data .= $extra;
}
}
// RLE8 压缩
else if ($compression == 1 && $bit == 8)
{
for ($j = $height – 1; $j >= 0; $j –)
{
$last_index = “\0″;
$same_num = 0;
for ($i = 0; $i <= $width; $i ++)
{
$index = imagecolorat($im, $i, $j);
if ($index !== $last_index || $same_num > 255)
{
if ($same_num != 0)
{
$bmp_data .= chr($same_num) . chr($last_index);
}

$last_index = $index;
$same_num = 1;
}
else
{
$same_num ++;
}
}

$bmp_data .= “\0\0″;
}

$bmp_data .= “\0\1″;
}

$size_quad = strlen($rgb_quad);
$size_data = strlen($bmp_data);
}
else
{
// 每行字节数必须为4的倍数,补齐。
$extra = ”;
$padding = 4 – ($width * ($bit / 8)) % 4;
if ($padding % 4 != 0)
{
$extra = str_repeat(“\0″, $padding);
}

// 位图数据
$bmp_data = ”;

for ($j = $height – 1; $j >= 0; $j –)
{
for ($i = 0; $i < $width; $i ++)
{
$index = imagecolorat($im, $i, $j);
$colors = imagecolorsforindex($im, $index);

if ($bit == 16)
{
$bin = 0 << $bit;

$bin |= ($colors['red'] >> 3) << 10;
$bin |= ($colors['green'] >> 3) << 5;
$bin |= $colors['blue'] >> 3;

$bmp_data .= pack(“v”, $bin);
}
else
{
$bmp_data .= pack(“c*”, $colors['blue'], $colors['green'], $colors['red']);
}

// todo: 32bit;
}

$bmp_data .= $extra;
}

$size_quad = 0;
$size_data = strlen($bmp_data);
$colors_num = 0;
}

// 位图文件头
$file_header = “BM” . pack(“V3″, 54 + $size_quad + $size_data, 0, 54 + $size_quad);

// 位图信息头
$info_header = pack(“V3v2V*”, 0×28, $width, $height, 1, $bit, $compression, $size_data, 0, 0, $colors_num, 0);

// 写入文件
if ($filename != ”)
{
$fp = fopen(“test.bmp”, “wb”);

fwrite($fp, $file_header);
fwrite($fp, $info_header);
fwrite($fp, $rgb_quad);
fwrite($fp, $bmp_data);
fclose($fp);

return 1;
}

// 浏览器输出
header(“Content-Type: image/bmp”);
echo $file_header . $info_header;
echo $rgb_quad;
echo $bmp_data;

return 1;
}
参考资料:BMP文件格式分析 (出处没有找到…)

原创文章,转载请注明出处。

出处:http://www.ugia.cn/?p=96

Popularity: 6%

asp

asp读取QQwry.dat

<%

‘=========================================================

‘ QQWry.DAT 利用程序 修改自互联网流传代码

‘ 本类在ASP环境中使用纯真版QQWry.dat通过完美测试

‘ 如果您的服务器环境不支持ADodb.Stream,将无法使用此程序

‘ 推荐使用纯真数据库,更新也方便

‘ ========================================================

‘ ============================================

‘ 返回IP信息

‘ ============================================

Function Look_Ip(IP)

Dim Wry, IPType, QQWryVersion, IpCounter

‘ 设置类对象

Set Wry = New TQQWry

‘ 开始搜索,并返回搜索结果

‘ 您可以根据 QQWry(IP) 返回值来判断该IP地址在数据库中是否存在,如果不存在可以执行其他的一些操作

‘ 比如您自建一个数据库作为追捕等,这里我就不详细说明了

IPType = Wry.QQWry(IP)

‘Tibet代码

if IPType = 0 then

if instr(Wry.localStr,”网通”)<>0 then

Look_Ip = “document.write(“”网通”");”

else

Look_Ip = “document.write(“”电信”");”

end if

else

Look_Ip = “document.write(“”电信”");”

end if

Exit Function

‘Tibet代码

‘ Country:国家地区字段

‘ LocalStr:省市及其他信息字段

Look_Ip = Wry.Country & ” ” & Wry.LocalStr

End Function

‘ ============================================

‘ 返回IP信息 JS调用

‘ ============================================

Function GetIpInfoAv(IP, sType)

Dim Wry, IPType

Set Wry = New TQQWry

IPType = Wry.QQWry(IP)

Select Case sType

Case 1 GetIpInfoAv = “document.write(“”" & IP & “”");”

Case 2 GetIpInfoAv = “document.write(“”" & Wry.Country & “”");”

Case 3 GetIpInfoAv = “document.write(“”" & Wry.LocalStr & “”");”

Case Else GetIpInfoAv = “document.write(“”您来自:” & IP & ” 所在区域:” & Wry.Country & ” ” & Wry.LocalStr & “”");”

End Select

End Function

‘ ============================================

‘ 返回QQWry信息(QQWry.Dat版本以及记录条数)

‘ ============================================

Function WryInfo()

Dim Wry, IPType, QQWry(1)

‘ 设置类对象

Set Wry = New TQQWry

IPType = Wry.QQWry(“255.255.255.255″)

‘ 读取数据库版本信息

QQWry(0) = Wry.Country & ” ” & Wry.LocalStr

‘ 读取数据库IP地址数目

QQWry(1) = Wry.RecordCount + 1

WryInfo = QQWry

End Function

‘ ============================================

‘ IP物理定位搜索类

‘ ============================================

Class TQQWry

‘ ============================================

‘ 变量声名

‘ ============================================

Dim Country, LocalStr, Buf, OffSet

Private StartIP, EndIP, CountryFlag

Public QQWryFile

Public FirstStartIP, LastStartIP, RecordCount

Private Stream, EndIPOff

‘ ============================================

‘ 类模块初始化

‘ ============================================

Private Sub Class_Initialize

Country = “”

LocalStr = “”

StartIP = 0

EndIP = 0

CountryFlag = 0

FirstStartIP = 0

LastStartIP = 0

EndIPOff = 0

QQWryFile = Server.MapPath(“QQWry.dat”) ‘QQ IP库路径,要转换成物理路径

End Sub

‘ ============================================

‘ IP地址转换成整数

‘ ============================================

Function IPToInt(IP)

Dim IPArray, i

IPArray = Split(IP, “.”, -1)

FOr i = 0 to 3

If Not IsNumeric(IPArray(i)) Then IPArray(i) = 0

If CInt(IPArray(i)) < 0 Then IPArray(i) = Abs(CInt(IPArray(i)))

If CInt(IPArray(i)) > 255 Then IPArray(i) = 255

Next

IPToInt = (CInt(IPArray(0))*256*256*256) + (CInt(IPArray(1))*256*256) + (CInt(IPArray(2))*256) + CInt(IPArray(3))

End Function

‘ ============================================

‘ 整数逆转IP地址

‘ ============================================

Function IntToIP(IntValue)

p4 = IntValue – Fix(IntValue/256)*256

IntValue = (IntValue-p4)/256

p3 = IntValue – Fix(IntValue/256)*256

IntValue = (IntValue-p3)/256

p2 = IntValue – Fix(IntValue/256)*256

IntValue = (IntValue – p2)/256

p1 = IntValue

IntToIP = Cstr(p1) & “.” & Cstr(p2) & “.” & Cstr(p3) & “.” & Cstr(p4)

End Function

‘ ============================================

‘ 获取开始IP位置

‘ ============================================

Private Function GetStartIP(RecNo)

OffSet = FirstStartIP + RecNo * 7

Stream.Position = OffSet

Buf = Stream.Read(7)

EndIPOff = AscB(MidB(Buf, 5, 1)) + (AscB(MidB(Buf, 6, 1))*256) + (AscB(MidB(Buf, 7, 1))*256*256)

StartIP = AscB(MidB(Buf, 1, 1)) + (AscB(MidB(Buf, 2, 1))*256) + (AscB(MidB(Buf, 3, 1))*256*256) + (AscB(MidB(Buf, 4, 1))*256*256*256)

GetStartIP = StartIP

End Function

‘ ============================================

‘ 获取结束IP位置

‘ ============================================

Private Function GetEndIP()

Stream.Position = EndIPOff

Buf = Stream.Read(5)

EndIP = AscB(MidB(Buf, 1, 1)) + (AscB(MidB(Buf, 2, 1))*256) + (AscB(MidB(Buf, 3, 1))*256*256) + (AscB(MidB(Buf, 4, 1))*256*256*256)

CountryFlag = AscB(MidB(Buf, 5, 1))

GetEndIP = EndIP

End Function

‘ ============================================

‘ 获取地域信息,包含国家和和省市

‘ ============================================

Private Sub GetCountry(IP)

If (CountryFlag = 1 or CountryFlag = 2) Then

Country = GetFlagStr(EndIPOff + 4)

If CountryFlag = 1 Then

LocalStr = GetFlagStr(Stream.Position)

‘ 以下用来获取数据库版本信息

If IP >= IPToInt(“255.255.255.0″) And IP <= IPToInt(“255.255.255.255″) Then

LocalStr = GetFlagStr(EndIPOff + 21)

Country = GetFlagStr(EndIPOff + 12)

End If

Else

LocalStr = GetFlagStr(EndIPOff + 8)

End If

Else

Country = GetFlagStr(EndIPOff + 4)

LocalStr = GetFlagStr(Stream.Position)

End If

‘ 过滤数据库中的无用信息

Country = Trim(Country)

LocalStr = Trim(LocalStr)

If InStr(Country, “CZ88.NET”) Then Country = “114XP.CN”

If InStr(LocalStr, “CZ88.NET”) Then LocalStr = “114XP.CN”

End Sub

‘ ============================================

‘ 获取IP地址标识符

‘ ============================================

Private Function GetFlagStr(OffSet)

Dim Flag

Flag = 0

Do While (True)

Stream.Position = OffSet

Flag = AscB(Stream.Read(1))

If(Flag = 1 or Flag = 2 ) Then

Buf = Stream.Read(3)

If (Flag = 2 ) Then

CountryFlag = 2

EndIPOff = OffSet – 4

End If

OffSet = AscB(MidB(Buf, 1, 1)) + (AscB(MidB(Buf, 2, 1))*256) + (AscB(MidB(Buf, 3, 1))*256*256)

Else

Exit Do

End If

Loop

If (OffSet < 12 ) Then

GetFlagStr = “”

Else

Stream.Position = OffSet

GetFlagStr = GetStr()

End If

End Function

‘ ============================================

‘ 获取字串信息

‘ ============================================

Private Function GetStr()

Dim c

GetStr = “”

Do While (True)

c = AscB(Stream.Read(1))

If (c = 0) Then Exit Do

‘如果是双字节,就进行高字节在结合低字节合成一个字符

If c > 127 Then

If Stream.EOS Then Exit Do

GetStrGetStr = GetStr & Chr(AscW(ChrB(AscB(Stream.Read(1))) & ChrB(C)))

Else

GetStrGetStr = GetStr & Chr(c)

End If

Loop

End Function

‘ ============================================

‘ 核心函数,执行IP搜索

‘ ============================================

Public Function QQWry(DotIP)

Dim IP, nRet

Dim RangB, RangE, RecNo

IP = IPToInt (DotIP)

Set Stream = CreateObject(“ADodb.Stream”)

Stream.Mode = 3

Stream.Type = 1

Stream.Open

Stream.LoadFromFile QQWryFile

Stream.Position = 0

Buf = Stream.Read(8)

FirstStartIP = AscB(MidB(Buf, 1, 1)) + (AscB(MidB(Buf, 2, 1))*256) + (AscB(MidB(Buf, 3, 1))*256*256) + (AscB(MidB(Buf, 4, 1))*256*256*256)

LastStartIP = AscB(MidB(Buf, 5, 1)) + (AscB(MidB(Buf, 6, 1))*256) + (AscB(MidB(Buf, 7, 1))*256*256) + (AscB(MidB(Buf, 8, 1))*256*256*256)

RecordCount = Int((LastStartIP – FirstStartIP)/7)

‘ 在数据库中找不到任何IP地址

If (RecordCount <= 1) Then

Country = “未知”

QQWry = 2

Exit Function

End If

RangB = 0

RangE = RecordCount

Do While (RangB < (RangE – 1))

RecNo = Int((RangB + RangE)/2)

Call GetStartIP (RecNo)

If (IP = StartIP) Then

RangB = RecNo

Exit Do

End If

If (IP > StartIP) Then

RangB = RecNo

Else

RangE = RecNo

End If

Loop

Call GetStartIP(RangB)

Call GetEndIP()

If (StartIP <= IP) And ( EndIP >= IP) Then

‘ 没有找到

nRet = 0

Else

‘ 正常

nRet = 3

End If

Call GetCountry(IP)

QQWry = nRet

End Function

‘ ============================================

‘ 类终结

‘ ============================================

Private Sub Class_Terminate

On ErrOr Resume Next

Stream.Close

If Err Then Err.Clear

Set Stream = Nothing

End Sub

End Class

%>

<% ‘——————调用方法 ——————%>

<% ‘——————0是显示样式类型——————%>

<%

set ip = request.ServerVariables(“REMOTE_ADDR”)

‘ip = “…ip…”

response.Write Look_Ip(ip)

%>

Popularity: 63%

php

php水印加强版

/*
* 功能:PHP图片水印 (水印支持图片或文字)
* 参数:
* $groundImage 背景图片,即需要加水印的图片,暂只支持GIF,JPG,PNG格式;
* $waterPos 水印位置,有10种状态,0为随机位置;
* 1为顶端居左,2为顶端居中,3为顶端居右;
* 4为中部居左,5为中部居中,6为中部居右;
* 7为底端居左,8为底端居中,9为底端居右;
* $waterImage 图片水印,即作为水印的图片,暂只支持GIF,JPG,PNG格式;
* $waterText 文字水印,即把文字作为为水印,支持ASCII码,不支持中文;
* $textFont 文字大小,值为1、2、3、4或5,默认为5;
* $textColor 文字颜色,值为十六进制颜色值,默认为#FF0000(红色);
*
* 注意:Support GD 2.0,Support FreeType、GIF Read、GIF Create、JPG 、PNG
* $waterImage 和 $waterText 最好不要同时使用,选其中之一即可,优先使用 $waterImage。
* 当$waterImage有效时,参数$waterString、$stringFont、$stringColor均不生效。
* 加水印后的图片的文件名和 $groundImage 一样。
* 作者:longware
*/
function imageWaterMark($groundImage,$waterPos=9,$waterImage=”",$waterText=”",$textFont=5,$textColor=”#FF0000″)
{
$isWaterImage = FALSE;
$formatMsg = “暂不支持该文件格式,请用图片处理软件将图片转换为GIF、JPG、PNG格式。”;
//读取水印文件
if(!empty($waterImage) && file_exists($waterImage))
{
$isWaterImage = TRUE;
$water_info = getimagesize($waterImage);
$water_w = $water_info[0];//取得水印图片的宽
$water_h = $water_info[1];//取得水印图片的高
switch($water_info[2])//取得水印图片的格式
{
case 1:$water_im = imagecreatefromgif($waterImage);break;
case 2:$water_im = imagecreatefromjpeg($waterImage);break;
case 3:$water_im = imagecreatefrompng($waterImage);break;
default:die($formatMsg);
}
}
//读取背景图片
if(!empty($groundImage) && file_exists($groundImage))
{
$ground_info = getimagesize($groundImage);
$ground_w = $ground_info[0];//取得背景图片的宽
$ground_h = $ground_info[1];//取得背景图片的高
switch($ground_info[2])//取得背景图片的格式
{
case 1:$ground_im = imagecreatefromgif($groundImage);break;
case 2:$ground_im = imagecreatefromjpeg($groundImage);break;
case 3:$ground_im = imagecreatefrompng($groundImage);break;
default:die($formatMsg);
}
}
else
{
die(“需要加水印的图片不存在!”);
}
//水印位置
if($isWaterImage)//图片水印
{
$w = $water_w;
$h = $water_h;
$label = “图片的”;
}
else//文字水印
{
$temp = imagettfbbox(ceil($textFont*2.5),0,”simfang.ttf”,$waterText);//取得使用 TrueType 字体的文本的范围
$w = $temp[2] – $temp[6];
$h = $temp[3] – $temp[7];
unset($temp);
$label = “文字区域”;
}
if( ($ground_w<$w) || ($ground_h<$h) )
{
echo “需要加水印的图片的长度或宽度比水印”.$label.”还小,无法生成水印!”;
return;
}
switch($waterPos)
{
case 0://随机
$posX = rand(0,($ground_w – $w));
$posY = rand(0,($ground_h – $h));
break;
case 1://1为顶端居左
$posX = 0;
$posY = 0;
break;
case 2://2为顶端居中
$posX = ($ground_w – $w) / 2;
$posY = 0;
break;
case 3://3为顶端居右
$posX = $ground_w – $w;
$posY = 0;
break;
case 4://4为中部居左
$posX = 0;
$posY = ($ground_h – $h) / 2;
break;
case 5://5为中部居中
$posX = ($ground_w – $w) / 2;
$posY = ($ground_h – $h) / 2;
break;
case 6://6为中部居右
$posX = $ground_w – $w;
$posY = ($ground_h – $h) / 2;
break;
case 7://7为底端居左
$posX = 0;
$posY = $ground_h – $h;
break;
case 8://8为底端居中
$posX = ($ground_w – $w) / 2;
$posY = $ground_h – $h;
break;
case 9://9为底端居右
$posX = $ground_w – $w;
$posY = $ground_h – $h;
break;
default://随机
$posX = rand(0,($ground_w – $w));
$posY = rand(0,($ground_h – $h));
break;
}
//设定图像的混色模式
imagealphablending($ground_im, true);
if($isWaterImage)//图片水印
{
imagecopy($ground_im, $water_im, $posX, $posY, 0, 0, $water_w,$water_h);//拷贝水印到目标文件
}
else//文字水印
{
if( !empty($textColor) && (strlen($textColor)==7) )
{
$R = hexdec(substr($textColor,1,2));
$G = hexdec(substr($textColor,3,2));
$B = hexdec(substr($textColor,5));
}
else
{
die(“水印文字颜色格式不正确!”);
}
//$waterText=iconv(‘utf-8′,’gbk’,$waterText);
imagestring ( $ground_im, $textFont, $posX, $posY, $waterText, imagecolorallocate($ground_im, $R, $G, $B));
}
//生成水印后的图片
@unlink($groundImage);
switch($ground_info[2])//取得背景图片的格式
{
case 1:imagegif($ground_im,$groundImage);break;
case 2:imagejpeg($ground_im,$groundImage);break;
case 3:imagepng($ground_im,$groundImage);break;
default:die($errorMsg);
}
//释放内存
if(isset($water_info)) unset($water_info);
if(isset($water_im)) imagedestroy($water_im);
unset($ground_info);
imagedestroy($ground_im);
}

//—————————————————————————————
if(isset($_FILES) && !empty($_FILES['userfile']) && $_FILES['userfile']['size']>0)
{
$uploadfile = “./”.time().”_”.$_FILES['userfile']['name'];
if (copy($_FILES['userfile']['tmp_name'], $uploadfile))
{
echo “OK
“;
//文字水印
imageWaterMark($uploadfile,9,”Noname.gif”,”www.nj-kingsway.com “,5,”#FF0000″);
//图片水印
//$waterImage=”./Hanweb_shuiyin.gif”;//水印图片路径
//imageWaterMark($uploadfile,0,$waterImage);
echo ““;
}
else
{
echo “Fail
“;
}
}
?>

文件:



Popularity: 2%

php

一个读取QQWry.dat的类及使用方法

类:class_qqwry.php


使用方法:


Popularity: 10%

javascript

根据URL获取主机名

function gethost(url)
{
var result = url.match(“^http:\/\/([^\/:]*)”);
if(result[1])
{
var domain = result[1].match(“[0-9a-zA-Z-]*\.(com\.tw|com\.cn|com\.hk|net\.cn|org\.cn|gov\.cn|ac\.cn|bj\.cn|sh\.cn|tj\.cn|cq\.cn|he\.cn|sx\.cn|nm\.cn|ln\.cn|jl\.cn|hl\.cn|js\.cn|zj\.cn|ah\.cn|fj\.cn|jx\.cn|sd\.cn|ha\.cn|hb\.cn|hn\.cn|gd\.cn|gx\.cn|hi\.cn|sc\.cn|gz\.cn|yn\.cn|xz\.cn|sn\.cn|gs\.cn|qh\.cn|nx\.cn|xj\.cn|tw\.cn|hk\.cn|mo\.cn|com|net|org|biz|info|cn|mobi|name|sh|ac|io|tw|hk|ws|travel|us|tm|cc|tv|la|in|中国|公司|网络)$”);
try{return domain[0]}catch(e){};
}
return false;
}

Popularity: 2%

javascript

获取一个页面元素在页面上的坐标位置

/*
obj-要获取其页面坐标的元素
enjoy收集整理 http://www.9enjoy.com
*/

function findPos(obj) {
var curleft = curtop = 0;
if (obj.offsetParent) {
curleft = obj.offsetLeft
curtop = obj.offsetTop
while (obj = obj.offsetParent) {
curleft += obj.offsetLeft
curtop += obj.offsetTop
}
}
return [curleft,curtop];
}

Popularity: 15%

javascript

获取页面参数

function GetLocationParam(param){ //获取页面参数
var request = {
QueryString : function(val) {
var uri = window.location.search;
var re = new RegExp(“” +val+ “=([^&?]*)”, “ig”);
return ((uri.match(re))?(uri.match(re)[0].substr(val.length+1)):null);
}
}
return request.QueryString(param);
}

js中就可以这样调用
如URL为http://www.itlearner.com/test.htm?name=hx

就可以把name的值赋给js中的name变量

Popularity: 3%