浏览模式: 标准 | 列表2006年11月的文章

新浪头条新闻图文切换效果

代码:
<title>代码演示专用页面</title>
<style type="text/css">
/* 全局CSS定义 */
body { text-align: center; margin:0; padding:0; background: #FFF; font-size:12px; color:#000;}
div,form,img,ul,ol,li,dl,dt,dd {margin: 0; padding: 0; border: 0;}
h1,h2,h3,h4,h5,h6 { margin:0; padding:0;}
table,td,tr,th{font-size:12px;}

/* 链接颜色 */
a:link {color: #000; text-decoration:none;}
a:visited {color: #83006f;text-decoration:none;}
a:hover {color: #c00; text-decoration:underline;}
a:active {color: #000;}
/* 颜色属性 [定义规则,小写c加颜色名称] */
.cRed,a.cRed:link,a.cRed:visited{ color:Red; }
.cBlue,a.cBlue:link,a.cBlue:visited{color:#1f3a87;}
a.cBlue:hover{color:#bc2931;}
.cDRed,a.cDRed:link,a.cDRed:visited{ color:#c00;}
.cGray,a.cGray:link,a.cGray:visited{ color: #4F544D;}
.cDGray,a.cDGray:link,a.cDGray:visited{ color: #666;}
.cWhite,a.cWhite:link,a.cWhite:visited{ color:#fff;}
.cBlack,a.cBlack:link,a.cBlack:visited{color:#000;}
a.cBlack:hover{color:#bc2931;}

/* 头图 */
.col{margin: 20 0 0 0;float:center; width:252px;border:1px solid #006BB6;}
.focusPic{margin:0 auto; width:252px;}
.focusPic .pic{margin:0 auto; width:250px; height:191px; padding:5px 0 0; background:url(http://cimg2.163.com/ent/n... no-repeat;}
.focusPic .pic img{margin:6px 0 0 0;}
.focusPic .pic h3 {text-align:left; padding:1px 0 0 12px;}
.focusPic .pic h3 img {margin:0px; }

.focusPic .pic .flashBlank {margin:0 auto; width:100%; height:6px; font-size:1px; }
.focusPic .pic h5 {text-align:left; padding:0px 0 0 12px !important;padding:5px 0 0 12px;}
.focusPic .pic h5 img {margin:0px; }

.focusPic h2{ float:left; width:236px;padding:4px 0 3px 12px; font-size:14px; text-align:left;}
.focusPic p{float:left; width:236px;line-height:160%; margin:0; text-align:left;padding:0 0 10px 12px; height:57px;}
.focusPic .more{ margin:0 auto; width:250px; }
.focusPic .more .textNum{float:right; margin:0 8px 0 0;padding:0 0 4px;}
.focusPic .more .textNum .text{float:left; font-weight:bold; padding:7px 6px 0 0; color:#666;}
.focusPic .more .textNum .num{float:left; width:113px; height:19px;}
.focusPic .more .textNum .bg1{ background:url(http://ent.163.com/newimg/...}
.focusPic .more .textNum .bg2{ background:url(http://ent.163.com/newimg/...}
.focusPic .more .textNum .bg3{ background:url(http://ent.163.com/newimg/...}
.focusPic .more .textNum .bg4{ background:url(http://ent.163.com/newimg/...}
.focusPic .more .textNum .num ul{ float:left; width:113px;}
.focusPic .more .textNum .num li{float:left; width:28px; font-weight:bold;display:block; color:#fff; list-style-type:none; padding:6px 0 0;}
.focusPic .more .textNum .num li a{color:#fff; padding:0 5px; }
.focusPic .more .textNum .num li a:visited{color:#fff;}
.focusPic .more .textNum .num li a:hover{color:#ff0;}
</style>
<div class="col">
<!-- 头图 -->
<script language="javascript">
var nn;
nn=1;
setTimeout("change_img()",6000);
function change_img()
{
if(nn>4) nn=1
setTimeout("setFocus1("+nn+")",6000);
nn++;
tt=setTimeout("change_img()",6000);
}
function setFocus1(i)
{
sel&#101;ctLayer1(i);
}
function sel&#101;ctLayer1(i)
{
switch(i)
{
case 1:
document.getElementById("focusPic1").style.display="block";
document.getElementById("focusPic2").style.display="none";
document.getElementById("focusPic3").style.display="none";
document.getElementById("focusPic4").style.display="none";
document.getElementById("focusPic1nav").style.display="block";
document.getElementById("focusPic2nav").style.display="none";
document.getElementById("focusPic3nav").style.display="none";
document.getElementById("focusPic4nav").style.display="none";
break;
case 2:
document.getElementById("focusPic1").style.display="none";
document.getElementById("focusPic2").style.display="block";
document.getElementById("focusPic3").style.display="none";
document.getElementById("focusPic4").style.display="none";
document.getElementById("focusPic1nav").style.display="none";
document.getElementById("focusPic2nav").style.display="block";
document.getElementById("focusPic3nav").style.display="none";
document.getElementById("focusPic4nav").style.display="none";
break;
case 3:
document.getElementById("focusPic1").style.display="none";
document.getElementById("focusPic2").style.display="none";
document.getElementById("focusPic3").style.display="block";
document.getElementById("focusPic4").style.display="none";
document.getElementById("focusPic1nav").style.display="none";
document.getElementById("focusPic2nav").style.display="none";
document.getElementById("focusPic3nav").style.display="block";
document.getElementById("focusPic4nav").style.display="none";
break;
case 4:
document.getElementById("focusPic1").style.display="none";
document.getElementById("focusPic2").style.display="none";
document.getElementById("focusPic3").style.display="none";
document.getElementById("focusPic4").style.display="block";
document.getElementById("focusPic1nav").style.display="none";
document.getElementById("focusPic2nav").style.display="none";
document.getElementById("focusPic3nav").style.display="none";
document.getElementById("focusPic4nav").style.display="block";
break;
}
}
</script>
<div class="focusPic">
<div id="focusPic1" style="display: block;">
        <div class="pic"> <a href="http://ent.163.com/06/0410... src="http://cimg2.163.com/ent/2... alt="章子怡黑衣蒙头上吴彦祖保姆车" width="228" height="150" border="0" /></a>
<h3><a href="http://adclient.163.com/ev...
,43,51,60,72,78,85,91,100,110,312,330,332,364,594,702,733,734&amp;Redirect=http://www.eiser.net/j_163_enter_spo1.htm"><img src="http://cimg2.163.com/ent/n... width="104" height="21" alt="" /></a></h3>
        </div>
<h2><a href="http://ent.163.com/06/0410...章子怡黑衣蒙头上吴彦祖保姆车</a></h2>
<p>  章子怡日前和霍启山闹分手,前晚(4月8日)在香港又被媒体跟拍到她和吴彦祖一起玩乐、还一上车就遮遮掩掩 <img src="http://cimg2.163.com/ent/n... alt="详细" width="3" height="13" /> <a href="http://ent.163.com/06/0410... class="cDRed">详细</a></p>
</div>
<div id="focusPic2" style="display: none;">
        <div class="pic"> <a href="http://ent.163.com/06/0410... src="http://cimg2.163.com/ent/2... alt="刘晓庆重演武则天造型曝光" width="228" height="150" border="0" /></a>
<h3><a href="http://adclient.163.com/ev...
,43,51,60,72,78,85,91,100,110,312,330,332,364,594,702,733,734&amp;Redirect=http://www.eiser.net/j_163_enter_spo1.htm"><img src="http://cimg2.163.com/ent/n... width="104" height="21" alt="" /></a></h3>
        </div>
<h2><a href="http://ent.163.com/06/0410...刘晓庆重演武则天造型曝光</a></h2>
<p>  《日月凌空》正紧张拍摄,刘晓庆再次扮演武则天,记者通过特殊渠道获得了两张被称为剧组顶级机密的造型照。 <img src="http://cimg2.163.com/ent/n... alt="详细" width="3" height="13" /> <a href="http://ent.163.com/06/0410... class="cDRed">详细</a></p>
</div>
<div id="focusPic3" style="display: none;">
        <div class="pic"> <a href="http://adclient.163.com/ev...,43,51,60,72,78,81,90,100,110,312,330,332,364,582,733,734&amp;Redirect=http://ent.163.com/special/00031SST/FQ.html"><img src="http://cimg2.163.com/ent/2... alt="赢飞利浦768手机" width="228" height="150" border="0" /></a>
<h3><a href="http://adclient.163.com/ev...
,43,51,60,72,78,85,91,100,110,312,330,332,364,594,702,733,734&amp;Redirect=http://www.eiser.net/j_163_enter_spo1.htm"><img src="http://cimg2.163.com/ent/n... width="104" height="21" alt="" /></a></h3>
        </div>
<h2><a href="http://adclient.163.com/ev...,43,51,60,72,78,81,90,100,110,312,330,332,364,582,733,734&amp;Redirect=http://ent.163.com/special/00031SST/FQ.html">赢飞利浦768手机</a></h2>
<p>  参加飞利浦手机娱乐关键字专题活动,赢取飞利浦768手机,活动正火热进行中 <img src="http://cimg2.163.com/ent/n... alt="详细" width="3" height="13" /> <a href="http://adclient.163.com/ev...,43,51,60,72,78,81,90,100,110,312,330,332,364,582,733,734&amp;Redirect=http://ent.163.com/special/00031SST/FQ.html" class="cDRed">详细</a></p>
</div>
<div id="focusPic4" style="display: none;">
        <div class="pic"><div class="clear flashBlank"> </div> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia...,0,29,0" width="228" height="150">
<param name="movie" value="http://cimg3.163.com/ent/2... />
<param name="quality" value="high" />
<embed src="http://cimg3.163.com/ent/2... quality="high" pluginspage="http://www.macromedia.com/... type="application/x-shockwave-flash" width="228" height="150"></embed>
</object>
<h5><a href="http://adclient.163.com/ev...
,43,51,60,72,78,85,91,100,110,312,330,332,364,594,702,733,734&amp;Redirect=http://http://www.eiser.net/j_163_enter_spo1.htm"><img src="http://cimg2.163.com/ent/n... width="104" height="21" alt="" /></a></h5>
        </div>
<h2><a href="http://adclient.163.com/ev...,43,51,60,72,78,84,91,100,110,312,330,332,364,586,702,733,734&amp;Redirect=http://pepsi.163.com/">中国无名小子挑战球星贝克汉姆</a></h2>
<p>  两个中国无名小子将会亲身与贝克汉姆、罗纳尔迪尼奥、亨利等世界顶级球星面对面。 <img src="http://cimg2.163.com/ent/n... alt="详细" width="3" height="13" /> <a href="http://adclient.163.com/ev...,43,51,60,72,78,84,91,100,110,312,330,332,364,586,702,733,734&amp;Redirect=http://pepsi.163.com/" class="cDRed">详细</a></p>
</div>
<div class="more">
<div class="textNum">
<div class="text">> 更多头图新闻</div>
<div class="num bg1" id="focusPic1nav" style="display: block;">
<ul>
<li>1</li><li><a href="javascript:setFocus1(2);" target="_self">2</a></li><li><a href="javascript:setFocus1(3);" target="_self">3</a></li><li><a href="javascript:setFocus1(4);" target="_self">4</a></li>
</ul>
</div>
<div class="num bg2" id="focusPic2nav" style="display: none;">
<ul>
<li><a href="javascript:setFocus1(1);" target="_self">1</a></li><li>2</li><li><a href="javascript:setFocus1(3);" target="_self">3</a></li><li><a href="javascript:setFocus1(4);" target="_self">4</a></li>
</ul>
</div>
<div class="num bg3" id="focusPic3nav" style="display: none;">
<ul>
<li><a href="javascript:setFocus1(1);" target="_self">1</a></li><li><a href="javascript:setFocus1(2);" target="_self">2</a></li><li>3</li><li><a href="javascript:setFocus1(4);" target="_self">4</a></li>
</ul>
</div>
<div class="num bg4" id="focusPic4nav" style="display: none;">
<ul>
<li><a href="javascript:setFocus1(1);" target="_self">1</a></li><li><a href="javascript:setFocus1(2);" target="_self">2</a></li><li><a href="javascript:setFocus1(3);" target="_self">3</a></li><li>4</li>
</ul>
</div>
</div>
</div>
</div>

Tags: 幻灯, 图片切换

JS图片按比例缩放,完美版支持动态网页的批量处理

代码:
<script language="JavaScript">
<!--
//图片按比例缩放
var flag=false;
function DrawImage(ImgD){
var image=new Image();
var iwidth = 150; //定义允许图片宽度
var iheight = 100; //定义允许图片高度
image.src=ImgD.src;
if(image.width>0 &amp;&amp; image.height>0){
flag=true;
if(image.width/image.height>= iwidth/iheight){
if(image.width>iwidth){
ImgD.width=iwidth;
ImgD.height=(image.height*iwidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}

ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>iheight){
ImgD.height=iheight;
ImgD.width=(image.width*iheight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
}
}
//调用:<img src="图片" onload="javascript:DrawImage(this)">
//-->
</script>

Tags: JS, 缩放

php验证类

代码:
<?php
class Validator{
/*************************************************
    Validator for PHP  β 服务器端脚本
    code by 我佛山人
    wfsr@cunite.com
    http://www.cunite.com
    modify:feifengxlq<许> http://www.phpobject.net/b...
demo:
$v = new Validator();
if(!$v->Validate(array("Name,名字只允许中文,chinese", "Nick, 只允许英文昵称, english", "Homepage, 主页Url格式不正确, url", "Password, 密码不符合安全规则, safe","Email,信箱格式错误,email", "QQ, QQ号码不存在, qq","Card, 身份证号码不正确, idcard","Phone, 电话号码不存在, phone","Mobile, 手机号码不存在, mobile","Zip, 邮政编码不存在, zip"))){
   echo $v->error();
}
*************************************************/
    var $error_item, $error_message, $error_mode, $error_no;
    function Validator($mode = 6){
        $this->error_mode = $mode;
        $this->error_no = 1;
    }

    function Validate($arr){
        if(is_array($arr)){
            $len = count($arr);
            for($i = 0; $i < $len; $i++){
                $this->is_valid($arr[$i]);
            }
        }

        if($this->error_no > 1)return false;
        return true;
    }

    function is_valid($str){
        $str = split(",", $str);
        if(count($str) < 3) return false;
        $name = trim($str[0]);
        $message = trim($str[1]);
        $data_type = trim($str[2]);
        $value = trim($_POST[$name]);

        switch($data_type){
            case "compare" :
                break;
            case "range" :
                break;
            case "repeat" :
                break;
            default :
                $method = "is_".$data_type;
                if(!$this->$method($value))
                    $this->add_error($name, $message);
                break;
        }
    }

    function add_error($name, $message){
        $this->error_item .= "," . $name;
        $this->error_message .= "," . $this->error_no . ":" . $message;
        $this->error_no ++;
    }

    function error($mode=""){
        $this->error_item = ereg_replace("^,+", "", $this->error_item);
        $this->error_message = ereg_replace("^,+", "", $this->error_message);
        $mode=(empty($mode))?$this->error_mode:$mode;
        switch($mode){
            case 4 :
                $info = "以下原因导致提交失败:\t\t\t\t,";
                echo "<script>alert(\"".join("\\n", split(",", $info . $this->error_message))."\")</script>";
                //print >>>end;
                break;
            case 5 :
                echo "输入有错误:<br /><ul><li>" . ereg_replace( "\b\d+:", "",join("</li><li>", split(",", $this->error_message))) . "</li></ul>";
                echo "<br /><a href="javascript:history.back()">返回</a>";
                exit;
                break;
            case 6:
                $info="输入有错误:<br /><ul><li>" . ereg_replace( "\b\d+:", "",join("</li><li>", split(",", $this->error_message))) . "</li></ul>";
                $info.="<br /><a href="javascript:history.back()">返回</a>";
                return $info;
            break;
        }
    }

    function is_email($str){
        return preg_match("/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/", $str);
    }

    function is_url($str){
        return preg_match("/^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&amp;_~`@[\]\":+!]*([^<>\"])*$/", $str);
    }

    function is_qq($str){
        return preg_match("/^[1-9]\d{4,8}$/", $str);
    }

    function is_zip($str){
        return preg_match("/^[1-9]\d{5}$/", $str);
    }

    function is_idcard($str){
        return preg_match("/^\d{15}(\d{2}[A-Za-z0-9])?$/", $str);
    }

    function is_chinese($str){
        return ereg("^[".chr(0xa1)."-".chr(0xff)."]+$",$str);
    }

    function is_english($str){
        return preg_match("/^[A-Za-z]+$/", $str);
    }

    function is_mobile($str){
        return preg_match("/^((\(\d{3}\))|(\d{3}\-))?13\d{9}$/", $str);
    }

    function is_phone($str){
        return preg_match("/^((\(\d{3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}$/", $str);
    }

    function is_safe($str){
        return (preg_match("/^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&amp;\*\.\(\)\[\]\{\}<>\?\\\/\"\"]*)|.{0,5})$|\s/", $str) != 0);
    }
}
?>


给一个简单的演示,也是我佛山人的。

代码:

<title>表单验证类 Validator for PHP β</title>
<style>
body,td{font:normal 12px Verdana;color:#333333}
input,textarea,sel&#101;ct,td{font:normal 12px Verdana;color:#333333;border:1px solid #999999;background:#ffffff}
table{border-collapse:collapse;}
td{padding:3px}
input{height:20;}
textarea{width:80%;height:50px;overfmin:auto;}
form{display:inline}
</style>
<table align="center">
<form action="validator.php" method="post">
<tr>
  <td>真实姓名:</td><td><input name="Name"></td>
</tr>
<tr>
  <td>英文名:</td><td><input name="Nick"></td>
</tr>
   <tr>
  <td>主页:</td><td><input name="Homepage"></td>
</tr>
<tr>
  <td>密码:</td><td><input name="Password"></td>
</tr>
<tr>
  <td>重复:</td><td><input name="Repeat"></td>
</tr>
<tr>
  <td>信箱:</td><td><input name="Email"></td>
</tr>
   <tr>
  <td>信箱:</td><td><input name="Email1"></td>
</tr>
<tr>
  <td>QQ:</td><td><input name="QQ"></td>
</tr>
   <tr>
  <td>身份证:</td><td><input name="Card"></td>
</tr>
<tr>
  <td>年龄:</td><td><input name="Year"></td>
</tr>
  <tr>
  <td>年龄1:</td><td><input name="Year1"></td>
</tr>
  <tr>
  <td>电话:</td><td><input name="Phone"></td>
</tr>
  <tr>
  <td>手机:</td><td><input name="Mobile"></td>
</tr>
    <tr>
  <td>生日:</td><td><input name="Birthday"></td>
</tr>
  <tr>
  <td>邮政编码:</td><td><input name="Zip"></td>
</tr>
<tr>
  <td>邮政编码:</td><td><input name="Zip1"></td>
</tr>
<tr>
  <td>操作系统:</td><td><sel&#101;ct name="OS"><option value="">选择您所用的操作系统</option><option value="Win98">Win98</option><option value="Win2k">Win2k</option><option value="WinXP">WinXP</option></sel&#101;ct></td>
</tr>
<tr>
  <td>所在省份:</td><td>广东<input name="Province" value="1" type="radio">陕西<input name="Province" value="2" type="radio">浙江<input name="Province" value="3" type="radio">江西<input name="Province" value="4" type="radio"></td>
</tr>
<tr>
  <td>爱好:</td><td>运动<input name="Favorite" value="1" type="checkbox">上网<input name="Favorite" value="2" type="checkbox">听音乐<input name="Favorite" value="3" type="checkbox">看书<input name="Favorite" value="4" type="checkbox"></td>
</tr>
  <td>自我介绍:</td><td><textarea name="Description">中文是一个字</textarea></td>
</tr>
    <td>自传:</td><td><textarea name="History">中文是两个字节t</textarea></td>
</tr>
<tr>
  <td colspan="2"><input name="Submit" type="submit" value="确定提交"></td>
</tr>
</form>
</table>

验证文件:
代码:

<?
require_once("Validator.class.php");
$v = new Validator();
if(!$v->Validate(array("Name,名字只允许中文,chinese", "Nick, 只允许英文昵称, english", "Homepage, 主页Url格式不正确, url", "Password, 密码不符合安全规则, safe","Email,信箱格式错误,email", "QQ, QQ号码不存在, qq","Card, 身份证号码不正确, idcard","Phone, 电话号码不存在, phone","Mobile, 手机号码不存在, mobile","Zip, 邮政编码不存在, zip"))){
   echo $v->error();
}
?>

Tags: , 验证

保存远程图片到本地 同时取得第一张图片并创建缩略图

采集中 或者 在线添加文章中 都可以用到此功能.
SNA新闻采集系统 For 3.62 (程序制作:ansir)里提取
以下是函数
代码:
<%
"==================================================
"函数名:CheckDir2
"作  用:检查文件夹是否存在
"参  数:FolderPath ------文件夹地址
"==================================================
Function CheckDir2(byval FolderPath)
    dim fso
    folderpath=Server.MapPath(".")&amp;"\"&amp;folderpath
    Set fso = Server.Cr&#101;ateObject("Scripting.FileSystemObject")
    If fso.FolderExists(FolderPath) then
    "存在
        CheckDir2 = True
    Else
    "不存在
        CheckDir2 = False
    End if
    Set fso = nothing
End Function
"==================================================
"函数名:MakeNewsDir2
"作  用:创建新的文件夹
"参  数:foldername ------文件夹名称
"==================================================
Function MakeNewsDir2(byval foldername)
    dim fso
    Set fso = Server.Cr&#101;ateObject("Scripting.FileSystemObject")
        fso.Cr&#101;ateFolder(Server.MapPath(".") &amp;"\" &amp;foldername)
        If fso.FolderExists(Server.MapPath(".") &amp;"\" &amp;foldername) Then
           MakeNewsDir2 = True
        Else
           MakeNewsDir2 = False
        End If
    Set fso = nothing
End Function
"==================================================
"函数名:DefiniteUrl
"作  用:将相对地址转换为绝对地址
"参  数:PrimitiveUrl ------要转换的相对地址
"参  数:ConsultUrl ------当前网页地址
"==================================================
Function DefiniteUrl(Byval PrimitiveUrl,Byval ConsultUrl)
   Dim ConTemp,PriTemp,Pi,Ci,PriArray,ConArray
   If PrimitiveUrl="" o&#114; ConsultUrl="" o&#114; PrimitiveUrl="$False$" Then
      DefiniteUrl="$False$"
      Exit Function
   End If
   If Left(ConsultUrl,7)<>"HTTP://" And Left(ConsultUrl,7)<>"http://" Then
      ConsultUrl= "http://" &amp; ConsultUrl
   End If
   ConsultUrl=Replace(ConsultUrl,"://",":\\")
   If Right(ConsultUrl,1)<>"/" Then
      If Instr(ConsultUrl,"/")>0 Then
         If Instr(Right(ConsultUrl,Len(ConsultUrl)-InstrRev(ConsultUrl,"/")),".")>0 then  
         Else
            ConsultUrl=ConsultUrl &amp; "/"
         End If
      Else
         ConsultUrl=ConsultUrl &amp; "/"
      End If
   End If
   ConArray=Split(ConsultUrl,"/")
   If Left(PrimitiveUrl,7) = "http://" then
      DefiniteUrl=Replace(PrimitiveUrl,"://",":\\")
   ElseIf Left(PrimitiveUrl,1) = "/" Then
      DefiniteUrl=ConArray(0) &amp; PrimitiveUrl
   ElseIf Left(PrimitiveUrl,2)="./" Then
      DefiniteUrl=ConArray(0) &amp; Right(PrimitiveUrl,Len(PrimitiveUrl)-1)
   ElseIf Left(PrimitiveUrl,3)="../" then
      Do While Left(PrimitiveUrl,3)="../"
         PrimitiveUrl=Right(PrimitiveUrl,Len(PrimitiveUrl)-3)
         Pi=Pi+1
      Loop            
      For Ci=0 to (Ubound(ConArray)-1-Pi)
         If DefiniteUrl<>"" Then
            DefiniteUrl=DefiniteUrl &amp; "/" &amp; ConArray(Ci)
         Else
            DefiniteUrl=ConArray(Ci)
         End If
      Next
      DefiniteUrl=DefiniteUrl &amp; "/" &amp; PrimitiveUrl
   Else
      If Instr(PrimitiveUrl,"/")>0 Then
         PriArray=Split(PrimitiveUrl,"/")
         If Instr(PriArray(0),".")>0 Then
            If Right(PrimitiveUrl,1)="/" Then
               DefiniteUrl="http:\\" &amp; PrimitiveUrl
            Else
               If Instr(PriArray(Ubound(PriArray)-1),".")>0 Then
                  DefiniteUrl="http:\\" &amp; PrimitiveUrl
               Else
                  DefiniteUrl="http:\\" &amp; PrimitiveUrl &amp; "/"
               End If
            End If      
         Else
            If Right(ConsultUrl,1)="/" Then  
               DefiniteUrl=ConsultUrl &amp; PrimitiveUrl
            Else
               DefiniteUrl=Left(ConsultUrl,InstrRev(ConsultUrl,"/")) &amp; PrimitiveUrl
            End If
         End If
      Else
         If Instr(PrimitiveUrl,".")>0 Then
            If Right(ConsultUrl,1)="/" Then
               If right(PrimitiveUrl,3)=".cn" o&#114; right(PrimitiveUrl,3)="com" o&#114; right(PrimitiveUrl,3)="net" o&#114; right(PrimitiveUrl,3)="org" Then
                  DefiniteUrl="http:\\" &amp; PrimitiveUrl &amp; "/"
               Else
                  DefiniteUrl=ConsultUrl &amp; PrimitiveUrl
               End If
            Else
               If right(PrimitiveUrl,3)=".cn" o&#114; right(PrimitiveUrl,3)="com" o&#114; right(PrimitiveUrl,3)="net" o&#114; right(PrimitiveUrl,3)="org" Then
                  DefiniteUrl="http:\\" &amp; PrimitiveUrl &amp; "/"
               Else
                  DefiniteUrl=Left(ConsultUrl,InstrRev(ConsultUrl,"/")) &amp; "/" &amp; PrimitiveUrl
               End If
            End If
         Else
            If Right(ConsultUrl,1)="/" Then
               DefiniteUrl=ConsultUrl &amp; PrimitiveUrl &amp; "/"
            Else
               DefiniteUrl=Left(ConsultUrl,InstrRev(ConsultUrl,"/")) &amp; "/" &amp; PrimitiveUrl &amp; "/"
            End If        
         End If
      End If
   End If
   If Left(DefiniteUrl,1)="/" then
     DefiniteUrl=Right(DefiniteUrl,Len(DefiniteUrl)-1)
   End if
   If DefiniteUrl<>"" Then
      DefiniteUrl=Replace(DefiniteUrl,"//","/")
      DefiniteUrl=Replace(DefiniteUrl,":\\","://")
   Else
      DefiniteUrl="$False$"
   End If
End Function
"==================================================
"函数名:ReplaceSaveRemoteFile
"作  用:替换、保存远程文件
"参  数:ConStr ------ 要替换的字符串
"参  数:StarStr ----- 前导
"参  数:OverStr -----
"参  数:IncluL ------
"参  数:IncluR ------
"参  数:SaveTf ------ 是否保存文件,False不保存,True保存
"参  数:SaveFilePath- 保存文件夹
"参  数: TistUrl------ 当前网页地址
"==================================================
Function ReplaceSaveRemoteFile(ConStr,StartStr,OverStr,IncluL,IncluR,SaveTf,SaveFilePath,TistUrl)
   If ConStr="$False$" o&#114; ConStr="" Then
      ReplaceSaveRemoteFile="$False$"
      Exit Function
   End If
   Dim TempStr,TempStr2,ReF,Matches,Match,Tempi,TempArray,TempArray2,OverTypeArray

   Set ReF = New Regexp
   ReF.IgnoreCase = True
   ReF.Global = True
   ReF.Pattern = "("&amp;StartStr&amp;").+?("&amp;OverStr&amp;")"
   Set Matches =ReF.Execute(ConStr)
   For Each Match in Matches
      If Instr(TempStr,Match.Value)=0 Then
         If TempStr<>"" then
            TempStr=TempStr &amp; "$Array$" &amp; Match.Value
         Else
            TempStr=Match.Value
         End if
      End If
   Next
   Set Matches=nothing
   Set ReF=nothing
   If TempStr="" o&#114; IsNull(TempStr)=True Then
      ReplaceSaveRemoteFile=ConStr
      Exit function
   End if
   If IncluL=False then
      TempStr=Replace(TempStr,StartStr,"")
   End if
   If IncluR=False then
      If Instr(OverStr,"|")>0 Then
         OverTypeArray=Split(OverStr,"|")
         For Tempi=0 To Ubound(OverTypeArray)
            TempStr=Replace(TempStr,OverTypeArray(Tempi),"")
         Next
      Else
         TempStr=Replace(TempStr,OverStr,"")
      End If  
   End if
   TempStr=Replace(TempStr,"""","")
   TempStr=Replace(TempStr,""","")

   Dim RemoteFile,RemoteFileurl,SaveFileName,SaveFileType,ArrSaveFileName,RanNum
   If Right(SaveFilePath,1)="/" then
      SaveFilePath=Left(SaveFilePath,Len(SaveFilePath)-1)
   End If
   If SaveTf=True then
      If CheckDir2(SaveFilePath)=False Then
         If MakeNewsDir2(SaveFilePath)=False Then
            SaveTf=False
         End If
      End If
   End If
   SaveFilePath=SaveFilePath &amp; "/"

   "图片转换/保存
   TempArray=Split(TempStr,"$Array$")
   For Tempi=0 To Ubound(TempArray)
      RemoteFileurl=DefiniteUrl(TempArray(Tempi),TistUrl)
      If RemoteFileurl<>"$False$" And SaveTf=True Then"保存图片
        ArrSaveFileName = Split(RemoteFileurl,".")
        SaveFileType=ArrSaveFileName(Ubound(ArrSaveFileName))"文件类型
        RanNum=Int(900*Rnd)+100
        SaveFileName = SaveFilePath&amp;year(now)&amp;month(now)&amp;day(now)&amp;hour(now)&amp;minute(now)&amp;second(now)&amp;ranNum&amp;"."&amp;SaveFileType                  
        Call SaveRemoteFile(SaveFileName,RemoteFileurl)
            ConStr=Replace(ConStr,TempArray(Tempi),SaveFileName)
      ElseIf RemoteFileurl<>"$False$" and SaveTf=False Then"不保存图片
            SaveFileName=RemoteFileUrl
            ConStr=Replace(ConStr,TempArray(Tempi),SaveFileName)
      End If
      If RemoteFileUrl<>"$False$" Then
         If UploadFiles="" then
            UploadFiles=SaveFileName
         Else
            UploadFiles=UploadFiles &amp; "|" &amp; SaveFileName
         End if
      End If
   Next  
   ReplaceSaveRemoteFile=ConStr
End function
"==================================================
"过程名:SaveRemoteFile
"作  用:保存远程的文件到本地
"参  数:LocalFileName ------ 本地文件名
"参  数:RemoteFileUrl ------ 远程文件URL
"==================================================
sub SaveRemoteFile(LocalFileName,RemoteFileUrl)
    dim Ads,Retrieval,GetRemoteData
    Set Retrieval = Server.Cr&#101;ateObject("Microsoft.XMLHTTP")
    With Retrieval
        .Open "Get", RemoteFileUrl, False, "", ""
        .Send
        GetRemoteData = .ResponseBody
    End With
    Set Retrieval = Nothing
    Set Ads = Server.Cr&#101;ateObject("Adodb.Stream")
    With Ads
        .Type = 1
        .Open
        .Write GetRemoteData
        .SaveToFile server.MapPath(LocalFileName),2
        .Cancel()
        .Close()
    End With
    Set Ads=nothing
end sub

"==================================================
"过程名:GetImg
"作  用:取得文章中第一张图片
"参  数:str ------ 文章内容
"参  数:strpath ------ 保存图片的路径
"==================================================
Function GetImg(str,strpath)
set objregEx = new RegExp
objregEx.IgnoreCase = true
objregEx.Global = true
zzstr=""&amp;strpath&amp;"(.+?)\.(jpg|gif|png|bmp)"
objregEx.Pattern = zzstr
set matches = objregEx.execute(str)
for each match in matches
retstr = retstr &amp;"|"&amp; Match.Value
next
if retstr<>"" then
Imglist=split(retstr,"|")
Imgone=replace(Imglist(1),strpath,"")
GetImg=Imgone
else
GetImg=""
end if
end function
%>

例:
代码:
<form id="form1" name="form1" method="post" action="?action=test">
  <textarea name="body" cols="50" rows="5" id="body">
<img height="180" src="http://cimg2.163.com/cnews... width="240" border="0" />
<img class="left"src="http://news.163.com/img/ne... width="114" />
<img height="60" src="http://cimg2.163.com/cnews... width="120" border="0" />
<img height="60" alt="中国维和人数大国之首" src="http://cimg2.163.com/cnews... width="120" border="0" />
  </textarea>
  <input type="submit" name="Submit" value="提交" />
</form>
<%
if request.QueryString("action")="test" then
    "图片开始的字符串
    FilesStartStr="src="
    "图片结束的字符串
    FilesOverStr="gif|jpg|bmp"
    "保存图片的文件夹
    FilesPath="qq"
    "取得保存图片的网站URL 自动判断是绝对 还是相对路径
    NewsUrl="http://news.163.com&#3...
    "取得文章内容
    Content =Request.Form("body")
    "开始保存图片
    Content=ReplaceSaveRemoteFile(Content,FilesStartStr,FilesOverStr,False,True,True,FilesPath,NewsUrl)
    "对新闻中的第一张图片创建缩略图
    if GetImg(Content,FilesPath)<>"" then
        Imgsrc=GetImg(Content,FilesPath)
        Imgsrc=replace(Imgsrc,FilesPath,"")
        Set Jpeg = Server.Cr&#101;ateObject("Persits.Jpeg")
        Path = Server.MapPath(""&amp;FilesPath&amp;"") &amp; "\"&amp;Imgsrc&amp;""
        Jpeg.Open Path
            "如果图片宽小于等于120 高小于等于90 则不创建缩略图
        if Jpeg.OriginalWidth<=120 and Jpeg.Height<=90 then
            Jpeg.Width = Jpeg.OriginalWidth
            Jpeg.Height = Jpeg.OriginalHeight
            Smallimg=FilesPath&amp;""&amp;GetImg(Content,FilesPath)
        else
            "图片宽度高度/2
            Jpeg.Width = Jpeg.OriginalWidth / 2
            Jpeg.Height = Jpeg.OriginalHeight / 2
            Jpeg.Save Server.MapPath(""&amp;FilesPath&amp;"") &amp; "\small_"&amp;Imgsrc&amp;""
            Smallimg=""&amp;FilesPath&amp;"/small_"&amp;Imgsrc&amp;""
        end if
    end if
    "显示结果
    response.Write("新闻中的第一张图片是:")
    response.Write("<img src="&amp;FilesPath&amp;"/"&amp;GetImg(Content,FilesPath)&amp;">")
    response.Write("<br>新闻中的第一张图片的缩略图是:")
    response.Write("<img src="&amp;Smallimg&amp;">")
    response.Write("<br>新的新闻内容(图片为本地):<br>")
    Response.Write(Content)
    Response.End()
end if
%>


Tags: 远程保存

ASP实现文件直接下载

主程序代码如下:(淡水河边这厮还没有用过)
--------------------------------------------------------------------------------
代码:
"定义所有需要使用的变量
Dim strFilename,S,Fso,F,intFilelength
strFilename = Server.MapPath(Trim(Request("File")))
Response.Buffer = True
Response.Clear
Set S = Server.Cr&#101;ateObject("ADODB.Stream")
S.Open
S.Type = 1
On Error Resume Next
Set Fso = Server.Cr&#101;ateObject("Scripting.FileSystemObject")
If Not Fso.FileExists(strFilename) Then
Response.Write("<h1>Error:</h1>"&amp;strFilename&amp;"你要下载的文件不存在!<p>")
Response.End
End If

Set F = Fso.GetFile(strFilename)
intFilelength = F.Size "获取文件大小
S.LoadFromFile(strFilename)
If Err Then
Response.Write("<h1>Error: </h1>Unknown Error!<p>")
Response.End
End If

Response.AddHeader "Content-Disposition","attachment;filename="&amp;F.name
Response.AddHeader "Content-Length",intFilelength
Response.CharSet = "GB2312"
Response.ContentType = "application/octet-stream"
Response.BinaryWrite S.Read
Response.Flush
S.Close
Set S = Nothing


对文本类文件(*.txt;*.html;*.doc;等等),图片类文件(*.jpg;*.gif等等)直接点击链接时会在浏览器打开,而无法出现下载保存对话框。
如果要实现点击上述文件,弹出保存对话框,则需要用到下面这个函数了:
代码:
<%
"Call downloadFile(Request("path"))

function downloadFile(strFile)
strFilename = server.MapPath(strFile)

"Clear the buffer
Response.Buffer = True
Response.Clear

"Cr&#101;ate stream
Set s = Server.Cr&#101;ateObject("ADODB.Stream")
s.Open

"Set as binary
s.Type = 1

"Load in the file
on error resume next

"Check the file exists
Set fso = Server.Cr&#101;ateObject("Scripting.FileSystemObject")
if not fso.FileExists(strFilename) then
Response.Write("<p><strong>Error: </strong>" &amp; strFilename &amp; " does not exist</p>")
Response.End
end if

"Get length of file
Set f = fso.GetFile(strFilename)
intFilelength = f.size

s.LoadFromFile(strFilename)
if err then
Response.Write("<p><strong>Error: </strong>" &amp; err.Description &amp; "</p>")
Response.End
end if

"Send the headers to the users browser
Response.AddHeader "Content-Disposition", "attachment; filename=" &amp; f.name
Response.AddHeader "Content-Length", intFilelength
Response.CharSet = "UTF-8"
Response.ContentType = "application/octet-stream"

"Output the file to the browser
Response.BinaryWrite s.Read
Response.Flush

"Tidy up
s.Close
Set s = Nothing

End Function
%>

Tags: 直接下载

记录分几列显示,也就是几行几列了

因为做到这样的案子,所以淡水河边分享一下.清晰明了呀
代码:
<table>
        <tr>
<%
    Set rs= Server.Cr&#101;ateObject("ADODB.Recordset")
    rs.open "sel&#101;ct id from [tbl] wh&#101;re the_type=1",conn,1,1
    tempnum=1
    do while not rs.eof
%>
<td><%=rs(0)%></td>
<%
    if (tempnum mod 3)=0 then response.write "</tr>" "3列显示mod 3
    tempnum=tempnum+1
    rs.movenext
    loop
%>
</tr>
<%
    rs.close
    set rs=nothing
%>
</table>

Tags: 几列, 几行几列

PJBLOG的验证码

PJBLOG的验证码,留个记号.用了
代码:
<%@CodePage="65001"%>
<%
Call Com_CreatValidCode("GetCode")

Sub Com_CreatValidCode(pSN)
    " 禁止缓存
    Response.Expires = -9999
    Response.AddHeader "Pragma","no-cache"
    Response.AddHeader "cache-ctrol","no-cache"
    "Response.ContentType = "Image/BMP"

    Randomize

    Dim i, ii, iii

    Const cOdds = 4 " 杂点出现的机率
    Const cAmount = 36 " 文字数量
    Const cCode = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"

    " 颜色的数据(字符,背景)
    Dim vColorData(1),vColorRandom(10)
    "vColorData(0) = ChrB(Int(Rnd*155)+100) &amp; ChrB(Int(Rnd*155)+100) &amp; ChrB(Int(Rnd*155)+100) " 蓝0,绿0,红0(黑色)
    vColorRandom(0)=ChrB(150) &amp; ChrB(0) &amp; ChrB(0)
    vColorRandom(1)=ChrB(0) &amp; ChrB(150) &amp; ChrB(0)
    vColorRandom(2)=ChrB(0) &amp; ChrB(0) &amp; ChrB(150)
    vColorRandom(3)=ChrB(0) &amp; ChrB(50) &amp; ChrB(150)
    vColorRandom(4)=ChrB(150) &amp; ChrB(50) &amp; ChrB(0)
    vColorRandom(5)=ChrB(150) &amp; ChrB(0) &amp; ChrB(150)
    vColorRandom(6)=ChrB(150) &amp; ChrB(100) &amp; ChrB(10)
    vColorRandom(7)=ChrB(150) &amp; ChrB(40) &amp; ChrB(120)
    vColorRandom(8)=ChrB(150) &amp; ChrB(0) &amp; ChrB(250)
    vColorRandom(9)=ChrB(100) &amp; ChrB(100) &amp; ChrB(100)
    vColorRandom(10)=ChrB(50) &amp; ChrB(50) &amp; ChrB(50)
    vColorData(0) = vColorRandom(0)
    vColorData(1) = ChrB(250) &amp; ChrB(250) &amp; ChrB(255) "背景色 蓝250,绿236,红211(浅蓝色)
    " 随机产生字符
    Dim vCode(4),vCodes,vCodeColors(4)
    For i = 0 To 3
        vCodeColors(i)=vColorRandom(Int(Rnd * 10))
        vCode(i) = Int(Rnd * cAmount)
        vCodes = vCodes &amp; Mid(cCode, vCode(i) + 1, 1)
    Next

    Session(pSN) = vCodes "记录入Session
    " 字符的数据
    Dim vNumberData(35)
    vNumberData(0) = "1110000111110111101111011110111101001011110100101111010010111101001011110111101111011110111110000111"
    vNumberData(1) = "1111011111110001111111110111111111011111111101111111110111111111011111111101111111110111111100000111"
    vNumberData(2) = "1110000111110111101111011110111111111011111111011111111011111111011111111011111111011110111100000011"
    vNumberData(3) = "1110000111110111101111011110111111110111111100111111111101111111111011110111101111011110111110000111"
    vNumberData(4) = "1111101111111110111111110011111110101111110110111111011011111100000011111110111111111011111111000011"
    vNumberData(5) = "1100000011110111111111011111111101000111110011101111111110111111111011110111101111011110111110000111"
    vNumberData(6) = "1111000111111011101111011111111101111111110100011111001110111101111011110111101111011110111110000111"
    vNumberData(7) = "1100000011110111011111011101111111101111111110111111110111111111011111111101111111110111111111011111"
    vNumberData(8) = "1110000111110111101111011110111101111011111000011111101101111101111011110111101111011110111110000111"
    vNumberData(9) = "1110001111110111011111011110111101111011110111001111100010111111111011111111101111011101111110001111"
    vNumberData(10) = "1111011111111101111111101011111110101111111010111111101011111100000111110111011111011101111000100011"
    vNumberData(11) = "1000000111110111101111011110111101110111110000111111011101111101111011110111101111011110111000000111"
    vNumberData(12) = "1110000011110111101110111110111011111111101111111110111111111011111111101111101111011101111110001111"
    vNumberData(13) = "1000001111110111011111011110111101111011110111101111011110111101111011110111101111011101111000001111"
    vNumberData(14) = "1000000111110111101111011011111101101111110000111111011011111101101111110111111111011110111000000111"
    vNumberData(15) = "1000000111110111101111011011111101101111110000111111011011111101101111110111111111011111111000111111"
    vNumberData(16) = "1110000111110111011110111101111011111111101111111110111111111011100011101111011111011101111110001111"
    vNumberData(17) = "1000100011110111011111011101111101110111110000011111011101111101110111110111011111011101111000100011"
    vNumberData(18) = "1100000111111101111111110111111111011111111101111111110111111111011111111101111111110111111100000111"
    vNumberData(19) = "1110000011111110111111111011111111101111111110111111111011111111101111111110111110111011111000011111"
    vNumberData(20) = "1000100011110111011111011011111101011111110001111111010111111101101111110110111111011101111000100011"
    vNumberData(21) = "1000111111110111111111011111111101111111110111111111011111111101111111110111111111011110111000000011"
    vNumberData(22) = "1000100011110010011111001001111100100111110101011111010101111101010111110101011111010101111001010011"
    vNumberData(23) = "1000100011110011011111001101111101010111110101011111010101111101100111110110011111011001111000110111"
    vNumberData(24) = "1110001111110111011110111110111011111011101111101110111110111011111011101111101111011101111110001111"
    vNumberData(25) = "1000000111110111101111011110111101111011110000011111011111111101111111110111111111011111111000111111"
    vNumberData(26) = "1110001111110111011110111110111011111011101111101110111110111011111011101001101111011001111110001011"
    vNumberData(27) = "1000001111110111011111011101111101110111110000111111010111111101101111110110111111011101111000110011"
    vNumberData(28) = "1110000011110111101111011110111101111111111001111111111001111111111011110111101111011110111100000111"
    vNumberData(29) = "1000000011101101101111110111111111011111111101111111110111111111011111111101111111110111111110001111"
    vNumberData(30) = "1000100011110111011111011101111101110111110111011111011101111101110111110111011111011101111110001111"
    vNumberData(31) = "1000100011110111011111011101111101110111111010111111101011111110101111111010111111110111111111011111"
    vNumberData(32) = "1001010011110101011111010101111101010111110101011111001001111110101111111010111111101011111110101111"
    vNumberData(33) = "1000100011110111011111101011111110101111111101111111110111111110101111111010111111011101111000100011"
    vNumberData(34) = "1000100011110111011111011101111110101111111010111111110111111111011111111101111111110111111110001111"
    vNumberData(35) = "1100000011110111011111111101111111101111111110111111110111111111011111111011111111101110111100000011"

    " 输出图像文件头
    Response.BinaryWrite ChrB(66) &amp; ChrB(77) &amp; ChrB(230) &amp; ChrB(4) &amp; ChrB(0) &amp; ChrB(0) &amp; ChrB(0) &amp; ChrB(0) &amp;_
    ChrB(0) &amp; ChrB(0) &amp; ChrB(54) &amp; ChrB(0) &amp; ChrB(0) &amp; ChrB(0) &amp; ChrB(40) &amp; ChrB(0) &amp;_
    ChrB(0) &amp; ChrB(0) &amp; ChrB(40) &amp; ChrB(0) &amp; ChrB(0) &amp; ChrB(0) &amp; ChrB(10) &amp; ChrB(0) &amp;_
    ChrB(0) &amp; ChrB(0) &amp; ChrB(1) &amp; ChrB(0)

    " 输出图像信息头
    Response.BinaryWrite ChrB(24) &amp; ChrB(0) &amp; ChrB(0) &amp; ChrB(0) &amp; ChrB(0) &amp; ChrB(0) &amp; ChrB(176) &amp; ChrB(4) &amp;_
    ChrB(0) &amp; ChrB(0) &amp; ChrB(18) &amp; ChrB(11) &amp; ChrB(0) &amp; ChrB(0) &amp; ChrB(18) &amp; ChrB(11) &amp;_
    ChrB(0) &amp; ChrB(0) &amp; ChrB(0) &amp; ChrB(0) &amp; ChrB(0) &amp; ChrB(0) &amp; ChrB(0) &amp; ChrB(0) &amp;_
    ChrB(0) &amp; ChrB(0)
    For i = 9 To 0 Step -1 " 历经所有行
        For ii = 0 To 3 " 历经所有字
            For iii = 1 To 10 " 历经所有像素
                " 逐行、逐字、逐像素地输出图像数据
                vColorData(0)=vCodeColors(ii)
                If Rnd * 99 + 1 < cOdds Then " 随机生成杂点
                    Response.BinaryWrite vColorData(0)
                Else
                    Response.BinaryWrite vColorData(Mid(vNumberData(vCode(ii)), i * 10 + iii, 1))
                End If
            Next
        Next
    Next
End Sub

%>

Tags: 验证码

支持自定义风格,默认4种显示模式的超强分页类

淡水河边这厮大致看了一下,很方便用的.有机会就用它了.
代码:

<?
/**
* filename: ext_page.class.php
* @package:phpbean
* @author :feifengxlq<feifengxlq#gmail.com>http://www.phpobject.net
* @copyright :Copyright 2006 feifengxlq
* @license:version 2.0
* @cr&#101;ate:2006-5-31
* @modify:2006-6-1
* @modify:feifengxlq 2006-11-4
* description:超强分页类,四种分页模式,默认采用类似baidu,google的分页风格。
* 2.0增加功能:支持自定义风格,自定义样式,同时支持PHP4和PHP5,
* to see detail,please visit http://www.phpobject.net/b...
* example:
* 模式四种分页模式:
   require_once("../libs/classes/page.class.php");
   $page=new page(array("total"=>1000,"perpage"=>20));
   echo "mode:1<br>".$page->show();
   echo "<hr>mode:2<br>".$page->show(2);
   echo "<hr>mode:3<br>".$page->show(3);
   echo "<hr>mode:4<br>".$page->show(4);
   开启AJAX:
   $ajaxpage=new page(array("total"=>1000,"perpage"=>20,"ajax"=>"ajax_page","page_name"=>"test"));
   echo "mode:1<br>".$ajaxpage->show();
   采用继承自定义分页显示模式:
   demo:http://www.phpobject.net/b...
*/
class page
{
/**
  * config ,public
  */
var $page_name="PB_page";//page标签,用来控制url页。比如说xxx.php?PB_page=2中的PB_page
var $next_page=">";//下一页
var $pre_page="<";//上一页
var $first_page="First";//首页
var $last_page="Last";//尾页
var $pre_bar="<<";//上一分页条
var $next_bar=">>";//下一分页条
var $format_left="[";
var $format_right="]";
var $is_ajax=false;//是否支持AJAX分页模式

/**
  * private
  *
  */
var $pagebarnum=10;//控制记录条的个数。
var $totalpage=0;//总页数
var $ajax_action_name="";//AJAX动作名
var $nowindex=1;//当前页
var $url="";//url地址头
var $offset=0;

/**
  * constructor构造函数
  *
  * @param array $array["total"],$array["perpage"],$array["nowindex"],$array["url"],$array["ajax"]...
  */
function page($array)
{
  if(is_array($array)){
     if(!array_key_exists("total",$array))$this->error(__FUNCTION__,"need a param of total");
     $total=intval($array["total"]);
     $perpage=(array_key_exists("perpage",$array))?intval($array["perpage"]):10;
     $nowindex=(array_key_exists("nowindex",$array))?intval($array["nowindex"]):"";
     $url=(array_key_exists("url",$array))?$array["url"]:"";
  }else{
     $total=$array;
     $perpage=10;
     $nowindex="";
     $url="";
  }
  if((!is_int($total))||($total<0))$this->error(__FUNCTION__,$total." is not a positive integer!");
  if((!is_int($perpage))||($perpage<=0))$this->error(__FUNCTION__,$perpage." is not a positive integer!");
  if(!empty($array["page_name"]))$this->set("page_name",$array["page_name"]);//设置pagename
  $this->_set_nowindex($nowindex);//设置当前页
  $this->_set_url($url);//设置链接地址
  $this->totalpage=ceil($total/$perpage);
  $this->offset=($this->nowindex-1)*$this->perpage;
  if(!empty($array["ajax"]))$this->open_ajax($array["ajax"]);//打开AJAX模式
}
/**
  * 设定类中指定变量名的值,如果改变量不属于这个类,将throw一个exception
  *
  * @param string $var
  * @param string $value
  */
function set($var,$value)
{
  if(in_array($var,get_object_vars($this)))
     $this->$var=$value;
  else {
   $this->error(__FUNCTION__,$var." does not belong to PB_Page!");
  }
  
}
/**
  * 打开倒AJAX模式
  *
  * @param string $action 默认ajax触发的动作。
  */
function open_ajax($action)
{
  $this->is_ajax=true;
  $this->ajax_action_name=$action;
}
/**
  * 获取显示"下一页"的代码
  *
  * @param string $style
  * @return string
  */
function next_page($style="")
{
  if($this->nowindex<$this->totalpage){
   return $this->_get_link($this->_get_url($this->nowindex+1),$this->next_page,$style);
  }
  return "<span class="".$style."">".$this->next_page."</span>";
}

/**
  * 获取显示“上一页”的代码
  *
  * @param string $style
  * @return string
  */
function pre_page($style="")
{
  if($this->nowindex>1){
   return $this->_get_link($this->_get_url($this->nowindex-1),$this->pre_page,$style);
  }
  return "<span class="".$style."">".$this->pre_page."</span>";
}

/**
  * 获取显示“首页”的代码
  *
  * @return string
  */
function first_page($style="")
{
  if($this->nowindex==1){
      return "<span class="".$style."">".$this->first_page."</span>";
  }
  return $this->_get_link($this->_get_url(1),$this->first_page,$style);
}

/**
  * 获取显示“尾页”的代码
  *
  * @return string
  */
function last_page($style="")
{
  if($this->nowindex==$this->totalpage){
      return "<span class="".$style."">".$this->last_page."</span>";
  }
  return $this->_get_link($this->_get_url($this->totalpage),$this->last_page,$style);
}

function nowbar($style="",$nowindex_style="")
{
  $plus=ceil($this->pagebarnum/2);
  if($this->pagebarnum-$plus+$this->nowindex>$this->totalpage)$plus=($this->pagebarnum-$this->totalpage+$this->nowindex);
  $begin=$this->nowindex-$plus+1;
  $begin=($begin>=1)?$begin:1;
  $return="";
  for($i=$begin;$i<$begin+$this->pagebarnum;$i++)
  {
   if($i<=$this->totalpage){
    if($i!=$this->nowindex)
        $return.=$this->_get_text($this->_get_link($this->_get_url($i),$i,$style));
    else
        $return.=$this->_get_text("<span class="".$nowindex_style."">".$i."</span>");
   }else{
    break;
   }
   $return.="n";
  }
  unset($begin);
  return $return;
}
/**
  * 获取显示跳转按钮的代码
  *
  * @return string
  */
function sel&#101;ct()
{
  $return="<sel&#101;ct name="PB_Page_Sel&#101;ct" >";
  for($i=1;$i<=$this->totalpage;$i++)
  {
   if($i==$this->nowindex){
    $return.="<option value="".$i."" sel&#101;cted>".$i."</option>";
   }else{
    $return.="<option value="".$i."">".$i."</option>";
   }
  }
  unset($i);
  $return.="</sel&#101;ct>";
  return $return;
}

/**
  * 获取mysql 语句中limit需要的值
  *
  * @return string
  */
function offset()
{
  return $this->offset;
}

/**
  * 控制分页显示风格(你可以增加相应的风格)
  *
  * @param int $mode
  * @return string
  */
function show($mode=1)
{
  switch ($mode)
  {
   case "1":
    $this->next_page="下一页";
    $this->pre_page="上一页";
    return $this->pre_page().$this->nowbar().$this->next_page()."第".$this->sel&#101;ct()."页";
    break;
   case "2":
    $this->next_page="下一页";
    $this->pre_page="上一页";
    $this->first_page="首页";
    $this->last_page="尾页";
    return $this->first_page().$this->pre_page()."[第".$this->nowindex."页]".$this->next_page().$this->last_page()."第".$this->sel&#101;ct()."页";
    break;
   case "3":
    $this->next_page="下一页";
    $this->pre_page="上一页";
    $this->first_page="首页";
    $this->last_page="尾页";
    return $this->first_page().$this->pre_page().$this->next_page().$this->last_page();
    break;
   case "4":
    $this->next_page="下一页";
    $this->pre_page="上一页";
    return $this->pre_page().$this->nowbar().$this->next_page();
    break;
   case "5":
    return $this->pre_bar().$this->pre_page().$this->nowbar().$this->next_page().$this->next_bar();
    break;
  }
  
}
/*----------------private function (私有方法)-----------------------------------------------------------*/
/**
  * 设置url头地址
  * @param: String $url
  * @return boolean
  */
function _set_url($url="")
{
  if(!empty($url)){
      //手动设置
   $this->url=$url.((stristr($url,"?"))?"&amp;":"?").$this->page_name."=";
  }else{
      //自动获取
   if(empty($_SERVER["QUERY_STRING"])){
       //不存在QUERY_STRING时
    $this->url=$_SERVER["REQUEST_URI"]."?".$this->page_name."=";
   }else{
       //
    if(stristr($_SERVER["QUERY_STRING"],$this->page_name."=")){
        //地址存在页面参数
     $this->url=str_replace($this->page_name."=".$this->nowindex,"",$_SERVER["REQUEST_URI"]);
     $last=$this->url[strlen($this->url)-1];
     if($last=="?"||$last=="&amp;"){
         $this->url.=$this->page_name."=";
     }else{
         $this->url.="&amp;".$this->page_name."=";
     }
    }else{
        //
     $this->url=$_SERVER["REQUEST_URI"]."&amp;".$this->page_name."=";
    }//end if    
   }//end if
  }//end if
}

/**
  * 设置当前页面
  *
  */
function _set_nowindex($nowindex)
{
  if(empty($nowindex)){
   //系统获取
  
   if(isset($_GET[$this->page_name])){
    $this->nowindex=intval($_GET[$this->page_name]);
   }
  }else{
      //手动设置
   $this->nowindex=intval($nowindex);
  }
}
  
/**
  * 为指定的页面返回地址值
  *
  * @param int $pageno
  * @return string $url
  */
function _get_url($pageno=1)
{
  return $this->url.$pageno;
}

/**
  * 获取分页显示文字,比如说默认情况下_get_text("<a href="">1</a>")将返回[<a href="">1</a>]
  *
  * @param String $str
  * @return string $url
  */
function _get_text($str)
{
  return $this->format_left.$str.$this->format_right;
}

/**
   * 获取链接地址
*/
function _get_link($url,$text,$style=""){
  $style=(empty($style))?"":"class="".$style.""";
  if($this->is_ajax){
      //如果是使用AJAX模式
   return "<a ".$style." href="javascript:".$this->ajax_action_name."("".$url."")">".$text."</a>";
  }else{
   return "<a ".$style." href="".$url."">".$text."</a>";
  }
}
/**
   * 出错处理方式
*/
function error($function,$errormsg)
{
     die("Error in file <b>".__FILE__."</b> ,Function <b>".$function."()</b> :".$errormsg);
}
}
?>



Tags: 分页,

文件上传前台控制检测程序

对恶意访问没有作用,但对正常访问者来说,确实方便了使用,改善了体验.
[html]
<body>
<title>文件上传前台控制检测程序 v0.6</title>
<style>
body,td{font-size:12px;}
</style>
<script language=javascript>

/*----------------------------------------
文件上传前台控制检测程序 v0.6

远程图片检测功能
检测上传文件类型

 检测图片文件格式是否正确
 检测图片文件大小
 检测图片文件宽度
 检测图片文件高度
图片预览

For 51js.com Author:333 Date:2005/08/26
Up&#100;ate:2005/09/03
-----------------------------------------*/

var ImgObj=new Image();//建立一个图像对象

var AllImgExt=".jpg|.jpeg|.gif|.bmp|.png|"//全部图片格式类型
var FileObj,ImgFileSize,ImgWidth,ImgHeight,FileExt,ErrMsg,FileMsg,HasCheked,IsImg//全局变量 图片相关属性

//以下为限制变量
var AllowExt=".jpg|.gif|.doc|.txt|"//允许上传的文件类型 0为无限制 每个扩展名后边要加一个"|" 小写字母表示
//var AllowExt=0
var AllowImgFileSize=70;//允许上传图片文件的大小 0为无限制 单位:KB
var AllowImgWidth=500;//允许上传的图片的宽度 0为无限制 单位:px(像素)
var AllowImgHeight=500;//允许上传的图片的高度 0为无限制 单位:px(像素)

HasChecked=false;

function CheckProperty(obj)//检测图像属性
{
FileObj=obj;
if(ErrMsg!="")//检测是否为正确的图像文件 返回出错信息并重置
{
ShowMsg(ErrMsg,false);
return false;//返回
}

if(ImgObj.readyState!="complete")//如果图像是未加载完成进行循环检测
{
setTimeout("CheckProperty(FileObj)",500);
return false;
}

ImgFileSize=Math.round(ImgObj.fileSize/1024*100)/100;//取得图片文件的大小
ImgWidth=ImgObj.width;//取得图片的宽度
ImgHeight=ImgObj.height;//取得图片的高度
FileMsg="\n图片大小:"+ImgWidth+"*"+ImgHeight+"px";
FileMsg=FileMsg+"\n图片文件大小:"+ImgFileSize+"Kb";
FileMsg=FileMsg+"\n图片文件扩展名:"+FileExt;

if(AllowImgWidth!=0&amp;&amp;AllowImgWidth<ImgWidth)
ErrMsg=ErrMsg+"\n图片宽度超过限制。请上传宽度小于"+AllowImgWidth+"px的文件,当前图片宽度为"+ImgWidth+"px";

if(AllowImgHeight!=0&amp;&amp;AllowImgHeight<ImgHeight)
ErrMsg=ErrMsg+"\n图片高度超过限制。请上传高度小于"+AllowImgHeight+"px的文件,当前图片高度为"+ImgHeight+"px";

if(AllowImgFileSize!=0&amp;&amp;AllowImgFileSize<ImgFileSize)
ErrMsg=ErrMsg+"\n图片文件大小超过限制。请上传小于"+AllowImgFileSize+"KB的文件,当前文件大小为"+ImgFileSize+"KB";

if(ErrMsg!="")
ShowMsg(ErrMsg,false);
else
ShowMsg(FileMsg,true);
}

ImgObj.onerror=function(){ErrMsg="\n图片格式不正确或者图片已损坏!"}

function ShowMsg(msg,tf)//显示提示信息 tf=true 显示文件信息 tf=false 显示错误信息 msg-信息内容
{
msg=msg.replace("\n","<li>");
msg=msg.replace(/\n/gi,"<li>");
if(!tf)
{
document.all.UploadButton.disabled=true;
FileObj.outerHTML=FileObj.outerHTML;
MsgList.innerHTML=msg;
HasChecked=false;
}
else
{
document.all.UploadButton.disabled=false;
if(IsImg)
PreviewImg.innerHTML="<img src=""+ImgObj.src+"" width="60" height="60">"
else
PreviewImg.innerHTML="非图片文件";
MsgList.innerHTML=msg;
HasChecked=true;
}
}

function CheckExt(obj)
{
ErrMsg="";
FileMsg="";
FileObj=obj;
IsImg=false;
HasChecked=false;
PreviewImg.innerHTML="预览区";
if(obj.value=="")return false;
MsgList.innerHTML="文件信息处理中...";
document.all.UploadButton.disabled=true;
FileExt=obj.value.substr(obj.value.lastIndexOf(".")).toLowerCase();
if(AllowExt!=0&amp;&amp;AllowExt.indexOf(FileExt+"|")==-1)//判断文件类型是否允许上传
{
ErrMsg="\n该文件类型不允许上传。请上传 "+AllowExt+" 类型的文件,当前文件类型为"+FileExt;
ShowMsg(ErrMsg,false);
return false;
}

if(AllImgExt.indexOf(FileExt+"|")!=-1)//如果图片文件,则进行图片信息处理
{
IsImg=true;
ImgObj.src=obj.value;
CheckProperty(obj);
return false;
}
else
{
FileMsg="\n文件扩展名:"+FileExt;
ShowMsg(FileMsg,true);
}

}

function SwitchUpType(tf)
{
if(tf)
str="<input type="file" name="file1" onchange="CheckExt(this)" style="width:180px;">"
else
str="<input type="text" name="file1" onblur="CheckExt(this)" style="width:180px;">"
document.all.file1.outerHTML=str;
document.all.UploadButton.disabled=true;
MsgList.innerHTML="";
}

</script>
<form enctype="multipart/form-data" method="POST" onsubmit="return HasChecked;">
<fieldset style="width: 372; height: 60;padding:2px;">
<legend><font color="#FF0000">图片来源</font></legend>
<input type="radio" name="radio1" checked onclick="SwitchUpType(true);">本地<input type="radio" name="radio1" onclick="SwitchUpType(false);">远程:<input type="file" name="file1" onchange="CheckExt(this)" style="width:180px;"> <input type="submit" id="UploadButton" value="开始上传" disabled><br/>
<div style="border:1 solid #808080;background:#E0E0E0;width100%;height:20px;color:#606060;padding:5px;">
<table border="0"><tr><td width="60" id="PreviewImg">预览区</td><td id="MsgList" valign="top"></td></tr></table>
</div>
</fieldset>
</form>

</body>

[/html]

Tags: 上传, 预览

CC攻击终极防范方法

什么是CC?
       CC就是模拟多个用户(多少线程就是多少用户)不停的进行访问(访问那些需要大量数据操作,就是需要大量CPU时间的页面).造成服务器资源消耗光,导致网站打不开!

防范代码如下,帖在你的CONN.ASP文件里面就OK了!1个小时后,会生成CCLog.txt,它的记录格式是:真实IP [代理的IP] 时间,看看哪个真实IP出现的次数多,就知道是谁在攻击了.
代码:
<%
Dim fsoObject
Dim tsObject
dim file
if Request.ServerVariables("HTTP_X_FORWARDED_FOR")="" then  
response.write "系统维护中"
response.end
end if
Set fsoObject = Server.Cr&#101;ateObject("Scripting.FileSystemObject")
file = server.mappath("CCLog.txt")
if not fsoObject.fileexists(file) then
fsoObject.cr&#101;atetextfile file,true,false
end if
set tsObject = fsoObject.OpenTextFile(file,8)
tsObject.Writeline Request.ServerVariables("HTTP_X_FORWARDED_FOR"&amp;"["&amp;Request.ServerVariables("REMOTE_ADDR")&amp;"]"&amp;now()
"Request.ServerVariables("REMOTE_ADDR") 取得访问者IP,如果访问者用了代理刚为代理的IP
" HTTP_X_FORWARDED_FOR,有部分代理会加上这个原始访问者IP(或是肉鸡的)
Set fsoObject = Nothing
Set tsObject = Nothing
response.write "系统维护中"
%>

     由于攻击者需要上百的代理,否则不能达到较好的效果,他很可能不会对代理进行一一验证匿名性,只要一发现某IP多次出现在代理中,就能确定他是攻击的本身或者是肉鸡了上面的代码不是防御的,而是发现攻击者的!在1个小时后,查看生成的CCLog.txt,获得攻击者的IP之后,就要删除了,不然连带正常访问都无法访问!

     而并不是每个代理服务器都能用 Request.ServerVariables("HTTP_X_FORWARDED_FOR") 来读取客户端的真实 IP,有些用此方法读取到的仍然是代理服务器的IP,同时因为网络的关系,攻击者要获得完全匿名的代理也是不难的,代理中国就有直接的匿名代理列表,这样是无法做到获取攻击者证据了.

直接防范代码如下:
代码:
<%
if request.servervariables("http_x_forwarded_for")<>""then
response.write"<fontcolor=#ff0000>您通过了代理服务器,"&amp;_"真实的IP为"&amp;request.servervariables("http_x_forwarded_for")
"这里把它添加到屏蔽IP中
response.end
end if
%>

Tags: 攻击, 防范, cc

Records:4312345