存档
ASP自杀脚本,很早以前写的一个遍历目录脚本,清空当前目录中所有的文件,请慎用。
< %
set fso=createobject("scripting.filesystemobject")
set fpos=fso.getfolder(server.mappath("."))
sub echo(t)
response.write t&vbCrlf
end sub
sub delpath(fpo)
for each file in fpo.files
echo "删除"&file
file.delete
next
for each path in fpo.subfolders
call delpath(path)
next
if fpo<>fpos then
echo "删除"&fpo
fpo.delete
end if
end sub
delpath(fpos)
echo "Game Over!"
%>
ASP也能处理JSON数据?呵呵,刚才在Pjblog论坛上看到一个兄弟写的文章,没有测试,不过理论上一定是可以的~ 太晚了,不测试了。
以前处理JSON太麻烦了,输出还好说,循环一下就可以了,解析真的很头疼。所以遇到 这种问题API问题,一般都是XML处理,不太喜欢,很麻烦。
<%
Dim sc4Json
Sub InitScriptControl
Set sc4Json = Server.CreateObject("MSScriptControl.ScriptControl")
sc4Json.Language = "JavaScript"
sc4Json.AddCode "var itemTemp=null;function getJSArray(arr, index){itemTemp=arr[index];}"
End Sub
Function getJSONObject(strJSON)
sc4Json.AddCode "var jsonObject = " & strJSON
Set getJSONObject = sc4Json.CodeObject.jsonObject
End Function
Sub getJSArrayItem(objDest,objJSArray,index)
[...]
JS有Base64.js,PHP内建Base64支持,ASP处理Base64数据就没有那么幸运了,既没有Base64.asp,也没有内建的函数,这可怎么办?
ASP一般用到Base64的时候,都是处理二进制文件。简单的文本,就没有必要编码咯。ASP处理二进制又是一个弱项,有没有好的方法呢?xml中的bin.base64也许可以拿来用用。
[asp]< %
'调用xml的编码,用于参照
function Base64Encode(strData)
dim objAds,objXd
set objAds=createobject("adodb.stream")
objAds.Type=2
objAds.charset="unicode"
objAds.mode=3
call objAds.open()
objAds.writeText strData
objAds.Position=0
objAds.Type=1
objAds.Position=2
[...]
又好久没有更新日志了,上次谈到将工作用的脚本换成php,现在发现这是一个非常非常明智的选择。
在Linux也可以直接用php当作脚本,处理工作的事情。也算是“跨平台脚本”咯~~~
今天说一下JS压缩,呵呵,这种工具我可写不出来,但是网上牛人已经帮我们写出了相应的类:JavaScriptPacker(http://creativecommons.org/licenses/LGPL/2.1/)
我们直接调用就可以咯,比如将test_resource.js压缩成test.js。
<?php
#demo.php
require_once ‘class.JavaScriptPacker.php’;
$packer = new JavaScriptPacker(file_get_contents("./test_resource.js"), ‘Normal’, true, false);
file_put_contents("./test.js",$packer->pack());
?>
直接 php demo.php
最近准备放弃使用许久的vbscript作为处理工作方面问题,而转向PHP。
应该是ASP转向PHP把,怎么是vbscript转向php?这个我要说一下,处理工作方面问题,比如通过API导个数据…用ASP,PHP在IIS中执行肯定不行,写个VBScript脚本,cscript 脚本名 让他执行吧,别的不用关了。所以用脚本处理些数据转换、导入导出还是不错的选择。
VBScript的致命的缺点是不支持引用文件,对HTTP请求方便不是很强,正则、XML处理起来不方面,JSON作为数据载体时就等着傻眼把。这是后用php作为脚本也是一个不错的选择。扯得有点远了,换成了php,数据库还是Access怎么办?这个简单,直接用com创建adodb实例即可。
现在已经创建好了数据库,只填写了部分域名,要通过php到域名查询接口返回whois信息,并存到Access数据库中,Access字段名已对应返回数组中的索引相同。
<?php
set_time_limit(0);
#因为要链接web,使用我前几天写的myhttp类。
include(‘myhttp.clsss.php’);
#API操作,这里直接忽略,里边有个get_domain_info来获取API返回的数据,并处理成数组。
include(‘api.function.php’);
$conn = new COM("Adodb.Connection");
$conn -> open("provider=microsoft.jet.oledb.4.0;data source=D:\myweb\miaoqiyuan.cn\test\php-linkdb\domain.mdb");
$dlist = new COM("ADODB.Recordset");
$rs = new COM("ADODB.Recordset");
$dlist -> open("select [domain],[did] from [domain] where isupdate=0",$conn,1,1);
while(!$dlist -> eof()){
echo "下载域名数据[".$dlist['domain']."].\n";
$d=get_domain_info($dlist['domain']);
$rs -> open("select * from [domain] where did=".$dlist['did'],$conn,3,2);
foreach($rs -> fields as $k => $v){
if($k >= 6){
$myvalue = [...]
最近一直在写淘宝客的程序,因为网络的原因,file_get_contents经常读取出错,想到了比较稳定的方法,使用fsockopen连接API。fsockopen 函数在网上介绍的还是很多的,但是介绍再多,创建http请求仍然是一件比较麻烦的。
fsockopen调用的方法比较繁琐,要使用得到的数据还要去掉http头,所以冒出了写一个通用的类的方法。今天正好是51假日,在家写了这种的一个类。
<?php
/*
CatSeven myHttp Vesion 0.1
======CopyRight======
Home:http://www.myw3.cn/myDevise/myHttp/
Design:Miao Qiyuan[miaoqiyuan.cn]
Downloads:http://downloads.myw3.cn/file=myDevise/myHttp/0.1
*/
class myHttp{
public $Method,$URI,$SendDate;
public $HttpServerPort,$HttpServer,$HttpServerIP;
public $Err,$ErrStr;
public $timeout;
public $responseText;
public function __construct($uri=’/',$method=’get’,$query=”,$server=’localhost’,$port=’80′,$serverip=”,$timeout=30){
$this->URI=$uri;
$this->Method=$method;
$this->SendDate=$query;
$this->HttpServer=$server;
$this->HttpServerPort=$port;
$this->HttpServerIP=$serverip;
if(is_numeric($timeout))$this->timeout=$timeout;
}
public function send(){
$this->Method=strtoupper($this->Method);
if($this->HttpServerIP=="")$this->HttpServerIP = $this->HttpServer;
if($this->Method=="GET" && strstr($this->URI,"?")==0)$this->URI=$this->URI."?".$this->SendDate;
$sock = fsockopen($this->HttpServerIP,$this->HttpServerPort,$errno,$errstr,$this->timeout);
if(!$sock){
$this->ErrStr=$errstr;
$this->Err=$errno;
die("无法打开".$this->HttpServerIP.":".$this->HttpServerPort);
}
fwrite($sock, $this->Method." ".$this->URI." HTTP/1.0\r\n");
fwrite($sock, "Host: ".$this->HttpServer."\r\n");
if($this->Method=="POST"){
fwrite($sock, "Content-type: application/x-www-form-urlencoded\r\n");
fwrite($sock, "Content-length: ".strlen($this->SendDate) . "\r\n");
fwrite($sock, "Accept: */*\r\n");
fwrite($sock, "\r\n");
fwrite($sock, $this->SendDate."\r\n");
fwrite($sock, "\r\n");
fwrite($sock, "Referer: http://www.myw3.cn/myDevise/myHttp/");
}
fwrite($sock, "Connection: Close\r\n\r\n");
$headers = "";
while ($str = trim(fgets($sock,4096)))
$headers .= "$str\n";
$body = [...]