苗启源的部落格Experience(经验) - http://www.miaoqiyuan.cn Fri, 30 Dec 2011 16:20:41 +0000 http://wordpress.org/?v=2.9.1 en hourly 1 iis7 404 自定义错误页 http://www.miaoqiyuan.cn/p/iis7-404-custom http://www.miaoqiyuan.cn/p/iis7-404-custom#comments Tue, 22 Mar 2011 03:57:16 +0000 mqycn http://www.miaoqiyuan.cn/?p=724    使用Windows7很久了,调试asp,php网站,一直没有问题。用这也算顺手,所以最近不准备换了。

    本站目录下的成语接龙最近流量恢复到了两三千IP左右,特别是二字开头的成语三字开头的成语四字开头的成语等文章给我带来了不菲的流量,为了再接再厉,准备在体验上再下些功夫。重新设计下成语接龙程序。本程序使用404.php,实现为静态。下载到本地调试,在IIS7中设置了404错误页竟然不行。

    查阅了很多资料,终于找到了解决办法,在web.config 找到httpErrors节点,修改为errorMode=”Custom”就可以了。

重启下IIS,现在就可以正常访问了。

]]>
http://www.miaoqiyuan.cn/p/iis7-404-custom/feed 0
ASP版本 文件转十六进制 http://www.miaoqiyuan.cn/p/asp-hexstring http://www.miaoqiyuan.cn/p/asp-hexstring#comments Wed, 20 Oct 2010 13:52:09 +0000 mqycn http://www.miaoqiyuan.cn/?p=707 最近接了一个彩信接口的网站,需要将 文本文件、图片文件 转换成 HexString,通过Form提交,.net、php、javascript的函数网上一抓一大把,asp的却不好找,今天我就来写一个asp版本的hexstring转换函数,为了方便以后用,直接写成类。

  class bin2txt
    dim adostream
    private sub class_initialize
      set adostream = server.createobject("ADODB.Stream")
      adostream.type = 1
      adostream.mode = 3
    end sub

    public sub open(fn)
      adostream.open
      adostream.LoadFromFile fn
    end sub

    public function getHex(t)
      dim tmp,hexstr,binstr
      binstr = adostream.read()
      for i = 1 to lenB(binstr)
        tmp = hex(ascB(midB(binstr,i,1)))
        if len(tmp) = 1 then tmp = "0" & tmp
        hexstr = hexstr & tmp & t
      next
      getHex = hexstr
    end function

    public function getOct(t)
      dim tmp,octstr,binstr
      binstr = adostream.read()
      for i = 1 to lenB(binstr)
        tmp = (ascB(midB(binstr,i,1)))
        if len(tmp) = 2 then tmp = "0" & tmp
        if len(tmp) = 1 then tmp = "00" & tmp
        octstr = octstr & tmp & t
      next
      getOct = octstr
    end function

  end class

使用方法,很简单,代码如下:

  set f = new bin2txt
  f.open server.mappath("sms/1.jpg")
  response.write f.getHex()

彩信添加桢也添加玩函数

'addpage
'pid:帧编号
'showtime:帧展示时间
function addpage(pid,showtime,ttype,tfile,ptype,pfile,mtype,mfile)
  addpage = "&d" & pid & "=" & showtime
  if ttype <> "" and ptype <> "" then
    f.open server.mappath(tfile)
    addpage = addpage & "&tt" & pid & "=" & ttype &_
                        "&tv" & pid & "=" & f.getHex()
  end if
  if ptype <> "" and ptype <> "" then
    f.open server.mappath(ptype)
    addpage = addpage & "&pt" & pid & "=" & ptype &_
            "&pv" & pid & "=" & f.getHex()
  end if
  if mtype <> "" and mtype <> "" then
    f.open server.mappath(mtype)
    addpage = addpage & "&mt" & pid & "=" & mtype &_
            "&mv" & pid & "=" & f.getHex()
  end if
end function

set f = new bin2txt
f.open server.mappath("sms/title.txt")
sendstr = "id=***&pwd=***&subject=" & f.getHex()
sendstr = sendstr & addpage(1,5,"txt","sms/1.txt","jpg","sms/1.jpg","","")
sendstr = sendstr & addpage(2,5,"txt","sms/2.txt","jpg","sms/2.jpg","","")
response.write openApi("http://118.144.76.79:8080/mmsServer/sendMms",sendstr)
]]>
http://www.miaoqiyuan.cn/p/asp-hexstring/feed 0
一分钟安装LAMP环境 http://www.miaoqiyuan.cn/p/lamp-install-1-minuts http://www.miaoqiyuan.cn/p/lamp-install-1-minuts#comments Fri, 25 Jun 2010 16:08:34 +0000 mqycn http://www.miaoqiyuan.cn/?p=655 联网下,一分钟安装LAMP环境。

Ubuntu下安装 apache2 + php5 + mysql 1. 安装运行环境
sudo apt-get install apache2
sudo apt-get install mysql-server
sudo apt-get install php5-common
sudo apt-get install php5-gd
sudo apt-get install php5-mysql
sudo apt-get install libapache2-mod-php5

apache2默认的 sites路径在
/var/www/sites

哈哈,很快把

2. 配置php5

sudo gedit /etc/php5/apache2/php.ini
修改允许最大使用内存,查找

memory_limit = 8M
修改为

memory_limit = 32M
修改允许最大上传尺寸,查找

upload_max_filesize = 2M
修改为

upload_max_filesize = 8M
允许 mysql 和 gd 模块,检查文件最后是否包含下面的代码,如果没有添加上。(默认是在配置文件最后有添加的,检查一下以防万一)

extension=mysql.so

extension=gd.so
保存并关闭文件。

3. 配置 mysql,让它支持其它客户端访问,如果你不需要就不用修改。

sudo gedit /etc/mysql/my.cnf
查找 文件

skip-networking
修改为

#skip-networking
保存并关闭文件。

重 新启动 mysql

sudo /etc/init.d/mysql restart
插入其它客户端访问用户(由于默认的帐号是 root@localhost,而客户端却使用root@localhost.localdomain 登录)

mysql -u root -e “GRANT ALL PRIVILEGES ON *.* TO root@localhost.localdomain

]]>
http://www.miaoqiyuan.cn/p/lamp-install-1-minuts/feed 0
从分区启动Linux http://www.miaoqiyuan.cn/p/boot-disk http://www.miaoqiyuan.cn/p/boot-disk#comments Sat, 19 Jun 2010 13:33:45 +0000 mqycn http://www.miaoqiyuan.cn/?p=634      以前的一台电脑,装好了CentOS,一直没用。当时考虑到把引导信息放到MBR中,以后不方便,所以把引导装到了硬盘分区。现在没法启动,郁闷。

     还好有一键Ghost。编辑menu.lst,去掉讨厌的密码。开机,选择一键ghost。c进入命令行模式。

     可能有的网友启动的时候会提示kernel panic-not syncing:Attempted to kill init!,这个原因就是root没有被正确传递的原因。

    ro root=LABEL=/ 或 ro root=(dh0,7)就可以了。

     忘了是那个分区了。

     grub>root (hd0,{Tab},哈哈,所有分区出来了。原来如此

     grub>root(hd0,7)

     grub>kernel  /boot/vmlinuz-2.6.9-78.EL ro root=LABEL=/

     grub>initrd /boot/initrd-2.6.9-78.EL.img

     grub>boot

      哈哈,熟悉的界面启动咯。

      也可以写到一键 Ghost 中的menu.lst里面,方便快速启动。

]]>
http://www.miaoqiyuan.cn/p/boot-disk/feed 0
CentOS HTTP安装 http://www.miaoqiyuan.cn/p/centos-http http://www.miaoqiyuan.cn/p/centos-http#comments Sat, 19 Jun 2010 12:43:05 +0000 mqycn http://www.miaoqiyuan.cn/?p=632     看了网上介绍的硬盘安装CentOS的文章,我也要试验一下。为了挑战难度,我准备以http方式安装。现在已经成功,主要操作步骤如下:

     1、U盘,32MB。我想没有比我这个更小把。安装好一键Ghost U盘版本。并修改GRUB的配置文件,将password一行去掉。

     2、电脑两台,一台裸机,一台装好Win2003的电脑,两台电脑通过switch相连

     3、在Windows 2003的电脑上装好IIS,并将CentOS包解压,通过http://10.0.0.254/install-centos/访问。

     4、裸机开机,U盘引导,进入GRUB菜单,c进入命令行,按提示输入:

grub>root (hd0,0) 
grub>kernel /vmlinuz
grub>initrd /initrd.img
grub>boot

     5、进入系统,等待,选择HTTP模式(FTP模式基本一样),按网络环境输入配置(dhcp模式我没有成功,我的win2003的dhcp是开着的)。如我的给他新配的ip  10.0.0.123。其他随便填,一个局域网的。

     6、填写http地址,我这里是10.0.0.254。路径是install-centos。下面按提示操作就可以了。很简单把。

    和硬盘光盘安装最大的不同,就是http方式不能用鼠标操作。总之没有硬盘光盘安装方便。可能是考虑到网速的原因把,值得一提的是。通过局域网方式安装,比硬盘速度块。

]]>
http://www.miaoqiyuan.cn/p/centos-http/feed 0
猫七原创ASP压缩解压系统 使用说明 http://www.miaoqiyuan.cn/p/webzip-demo http://www.miaoqiyuan.cn/p/webzip-demo#comments Sat, 27 Mar 2010 13:51:55 +0000 mqycn http://www.miaoqiyuan.cn/?p=544

1.下载&安装

       到http://www.miaoqiyuan.cn/products/webzip.rar,保存为webzip.rar以供备用。

2.压缩

       将webzip.rar中的webzip.asp、webzip.asp.webzip解压到要压缩的目录。在浏览器中访问[hostname]/[保存路径]/webzip.asp打开本工具,点击压缩,稍等片刻,即可打包完毕。

3.上传

     将webzip.asp、webzip.asp.webzip通过FTP或在线文件管理系统上传到您的站点目录。

4.解压

     在浏览器中访问[hostname]/[保存路径]/webzip.asp,选择解压。稍等片刻,您的整个站点将会在服务服务器上解压完毕。

    至此,您的整个站点即可正常使用了。

[Debug]
1.ADODB.Stream读取asp文件时,如果文件结尾为%>,则%后的>会被忽略掉,现在本人暂未解决这个问题,用户可以在以%>结尾的asp文件,请在后边添加一个空格或换行符,恢复后程序即可正常使用。

2.如果您在使用中发现出现某些问题,可直接致邮:mqycn@126.com

]]>
http://www.miaoqiyuan.cn/p/webzip-demo/feed 0
给dedeims添加在线支付的功能之数据库设置 http://www.miaoqiyuan.cn/p/dedeims-online-pay http://www.miaoqiyuan.cn/p/dedeims-online-pay#comments Tue, 23 Mar 2010 15:39:50 +0000 mqycn http://www.miaoqiyuan.cn/?p=524 刚改VPS出问题了,现在刚解决好,原来打算多写几篇关于dedeims的文件,无奈现在太晚了,先写一篇 给dedeims添加在线支付的功能之数据库设置 ,页面代码等改天整理好再发。

--为会员添加余额
ALTER TABLE `dede_member` ADD `money` DOUBLE(11,2) Default 0 NOT NULL AFTER `scores`
ALTER TABLE `dede_member` ADD `moneyto` DOUBLE(11,2) Default 0 NOT NULL AFTER `money`

--添加充值记录
--paytype 0:在线充值;1:提现;2:积分兑换
DROP TABLE IF EXISTS `dede_paylog`;
CREATE TABLE IF NOT EXISTS `dede_paylog` (
  `id` mediumint(8) NOT NULL auto_increment,
  `mid` mediumint(8) NOT NULL,
  `paytype` smallint(5) NOT NULL,
  `money` DOUBLE(11,2) Default 0 NOT NULL,
  `money_s` DOUBLE(11,2) Default 0 NOT NULL,
  `money_e` DOUBLE(11,2) Default 0 NOT NULL,
  `dateline` int(10) NOT NULL,
  `desc` char(255) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET='utf8' AUTO_INCREMENT=1000000;
]]>
http://www.miaoqiyuan.cn/p/dedeims-online-pay/feed 1
给华众的Other业务添加一个续费提醒,新注册业务的提醒 http://www.miaoqiyuan.cn/p/hzhost_other_newreg http://www.miaoqiyuan.cn/p/hzhost_other_newreg#comments Sat, 20 Mar 2010 14:18:04 +0000 mqycn http://www.miaoqiyuan.cn/?p=521 待处理申请业务</a> <a class=commonface href="ot2_lst.asp?querytype=176">待处理续费业务</a> 处理日期的程序: < % 's_exptme 业务到期日期 'sid 业务ID set rs=server.createobject("ADODB.recordset") rs.open "select * from malst where ma_otstr='ot2' and ma_otid="&sid,conn,3,2 if rs.eof then rs.addnew rs("ma_otstr")="ot2" rs("ma_otid")=sid rs("ma_lastdate")=s_exptme+1 else rs("ma_lastdate")=s_exptme+1 end if rs.update rs.close set rs=nothing %> 如果other产品有产品,请用以下代码升级。 'Name:addLastManager.vbs 'Desc:给所有ot型业务添加lastmanager记录 'Auth:猫七(Miaoqiyuan.cn) set conn=createobject("ADODB.connection") conn.open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=hzhost7;Password=********;Initial Catalog=hzhost7;Data Source=********" set rs=conn.execute("select [...]]]> 给华众的Other业务添加一个续费提醒,新注册业务的提醒

华众程序的用户,应该有很多人用过Other类型的产品。但是Other产品有一个缺点,那就是会员新注业务和续费业务没有提醒。这样就增大了该类产品的维护成本(时间)。今天我给大家带来一种解决方案。

我们以ot2为例,在ot2lst中添加字段肯定是不可取的方案,我的方案是添加一个表。malst,字段设置如下:
ma_id 自动编号
ma_otid 对应的ot2list.s_id
ma_otstr ot2,如果改成ot1,ma_otid就是ot1lst.s_id
ma_lastdate 到期日期+1天

加表的好处如下:无需修改任何子平台,主平台只需修改后台的1个文件。
原理如下:
1.新注册业务,ma_lastdate字段为空,我们处理后,值变成了到期日期+1天
2.续费业务,到期日期比原来有所增加,但是ma_lastdate字段并未变化,所以查询到期日期

需要修改视图:

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

ALTER    VIEW dbo.v_ot2lst
AS

SELECT dbo.pdtlst.*, dbo.ot2lst.*, dbo.memlst.u_rotnme AS u_rotnme,
      dbo.memlst.u_myare AS u_myare, dbo.memlst.u_nme AS u_nme,
      dbo.memlst.u_eml AS u_eml, dbo.memlst.u_fatstr AS u_fatstr,
      dbo.memlst.u_fatnme AS u_fatnme,dbo.malst.ma_lastdate as lastmanager
FROM dbo.ot2lst LEFT OUTER JOIN
      dbo.pdtlst ON dbo.ot2lst.s_prd = dbo.pdtlst.g_prd LEFT OUTER JOIN
      dbo.memlst ON dbo.ot2lst.s_unme = dbo.memlst.u_nme LEFT JOIN dbo.malst on dbo.malst.ma_otid=dbo.ot2lst.s_id and dbo.malst.ma_otstr=’ot2′

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

在判断中添加:
master/ot2_mng/ot2_lst.asp中添加判断。
elseif querytype=175 then
	qstring=qstring&" and lastmanager is null"
elseif querytype=176 then
	qstring=qstring&" and lastmanager is not null and s_exptme>lastmanager"

在合适的位置添加链接:

            <a class=commonface   href="ot2_lst.asp?querytype=175">待处理申请业务</a>
            <a class=commonface   href="ot2_lst.asp?querytype=176">待处理续费业务</a>

处理日期的程序:

< %
's_exptme	业务到期日期
'sid		业务ID

set rs=server.createobject("ADODB.recordset")
rs.open "select * from malst where ma_otstr='ot2' and ma_otid="&sid,conn,3,2
if rs.eof then
	rs.addnew
	rs("ma_otstr")="ot2"
	rs("ma_otid")=sid
	rs("ma_lastdate")=s_exptme+1
else
	rs("ma_lastdate")=s_exptme+1
end if
rs.update
rs.close
set rs=nothing
%>

如果other产品有产品,请用以下代码升级。

'Name:addLastManager.vbs
'Desc:给所有ot型业务添加lastmanager记录
'Auth:猫七(Miaoqiyuan.cn)

set conn=createobject("ADODB.connection")
conn.open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=hzhost7;Password=********;Initial Catalog=hzhost7;Data Source=********"

set rs=conn.execute("select * from ot2lst where s_id>10000000")
do while not rs.eof
	if conn.execute("select * from malst where ma_otstr='ot2' and ma_otid="&rs("s_id")).eof then
		conn.execute("insert into malst(ma_otstr,ma_otid,ma_lastdate)values('ot2',"&rs("s_id")&",'"&rs("s_exptme")+1&"')")
		wscript.echo "insert into:"&rs("s_id")
	else
		wscript.echo rs("s_id")&" ishave."
	end if
	rs.movenext
loop

]]> http://www.miaoqiyuan.cn/p/hzhost_other_newreg/feed 1 写的一个简单的PHP缓存类 http://www.miaoqiyuan.cn/p/php-cache-class http://www.miaoqiyuan.cn/p/php-cache-class#comments Thu, 21 Jan 2010 17:09:46 +0000 mqycn http://www.miaoqiyuan.cn/?p=492 U = $URI; $this->K = md5($URI); $this->P = $P; $this->Par = $Par; $this->E = '.tmp_miaoqiyuan'; $this->F = $this->Par . $this->P . '/' . $this->K . $this->E; } public function getCache(){ if(!!($fp=@fopen($this->F,'r'))){ $html=fread($fp,102400); }else{ $html=file_get_contents($this->U); $this->addIndex(); $fp=fopen($this->F,'w'); fwrite($fp,$html); } fclose($fp); return $html; } public function noCache(){ $html=file_get_contents($this->U); $fp=fopen($this->F,'w'); fwrite($fp,$html); fclose($fp); return $html; } public function flushCache(){ unlink($this->F); } public function addIndex(){ $fpidx=fopen($this->Par . $this->P . '.rtf','a'); fwrite($fpidx,$this->K . ' ' .$this->U); fclose($fpidx); } } ?> 用的时候很简单 require_once('./inc/404cache.php'); $Cache=new cache404($URI,$Path); #echo $Cache->noCache(); echo $Cache->getCache(); < ?php require_once('./inc/404cache.php'); $q=explode("/",$URI=substr(($qs = strtolower($_SERVER['QUERY_STRING'])),strpos($qs, ':80')+4)); $URI="/".$URI; switch($q[0]){ case 'test': #/test -> /seo_test/test.asp if(preg_match('/^\/test(\/)?$/',$URI)){ $URI='http:'.'//'.$_SERVER['SERVER_NAME'].'/seo_test/test.asp'; } #/test/[a-z]\.html -> /seo_test/test.asp?key=$1 else [...]]]> 前几天写过一篇巧用404.php解决Wordpress耗资源的问题,给Wordpress加个缓存功能(http://www.miaoqiyuan.cn/p/wordpress-haoziyuan-wordpress-cache)中提到了PHP缓存的方法,总感觉不是很方便,现在我又写了一个新的。

< ?php
	class cache404{
		public $K,$P;
		public function __construct($URI,$P='blog',$Par='./cache/'){
			$this->U = $URI;
			$this->K = md5($URI);
			$this->P = $P;
			$this->Par = $Par;
			$this->E = '.tmp_miaoqiyuan';
			$this->F = $this->Par . $this->P . '/' . $this->K . $this->E;
		}
		public function getCache(){
			if(!!($fp=@fopen($this->F,'r'))){
				$html=fread($fp,102400);
			}else{
				$html=file_get_contents($this->U);
				$this->addIndex();
				$fp=fopen($this->F,'w');
				fwrite($fp,$html);
			}
			fclose($fp);
			return $html;
		}
		public function noCache(){
			$html=file_get_contents($this->U);
			$fp=fopen($this->F,'w');
			fwrite($fp,$html);
			fclose($fp);
			return $html;
		}
		public function flushCache(){
			unlink($this->F);
		}
		public function addIndex(){
			$fpidx=fopen($this->Par . $this->P . '.rtf','a');
			fwrite($fpidx,$this->K . '	' .$this->U);
			fclose($fpidx);
		}
}
?>

用的时候很简单

	require_once('./inc/404cache.php');
	$Cache=new cache404($URI,$Path);
	#echo $Cache->noCache();
	echo $Cache->getCache();
< ?php
	require_once('./inc/404cache.php');
	$q=explode("/",$URI=substr(($qs = strtolower($_SERVER['QUERY_STRING'])),strpos($qs, ':80')+4));
	$URI="/".$URI;
	switch($q[0]){
		case 'test':
			#/test	->	/seo_test/test.asp
			if(preg_match('/^\/test(\/)?$/',$URI)){
				$URI='http:'.'//'.$_SERVER['SERVER_NAME'].'/seo_test/test.asp';
			}

			#/test/[a-z]\.html	->	/seo_test/test.asp?key=$1
			else if(preg_match('/^\/test\/([a-z])\.html$/',$URI,$Match)){
				$URI='http:'.'//'.$_SERVER['SERVER_NAME'].'/seo_test/test.asp?key='.$Match[1];
			}else{
				$URI='http:'.'//'.$_SERVER['SERVER_NAME'].'/seo_test/test.asp';
			}
			$Path='test';
		default:
			$URI='http:'.'//'.$_SERVER['SERVER_NAME'].'/index.php'.$URI;
			$Path='blog';
	}
	$Cache=new cache404($URI,$Path);
	#echo $Cache->getCache();
	echo $Cache->noCache();
?>
]]>
http://www.miaoqiyuan.cn/p/php-cache-class/feed 0
ISAPI_Rewrite不起作用的N种原因 http://www.miaoqiyuan.cn/p/isapi-rewrite-err http://www.miaoqiyuan.cn/p/isapi-rewrite-err#comments Thu, 21 Jan 2010 16:59:19 +0000 mqycn http://www.miaoqiyuan.cn/?p=490 现在经常用到ISAPI_Rewrite,遇到的问题就是在本地测试的时候,一切没有问题,到服务器上,竟然不起作用。郁闷~
经过我的一些探索,发现了比起作用的原因如下:
1、IIS_WPG对ISAPI_Rewrite.dll没有读取的权限
2、IIS_WPG对httpd.ini没有读取的权限
3、IIS_WPG对站点目录中的httpd.ini没有读取的权限(用于每个站点有独立的httpd.ini)。
4、IIS_WPG对站点目录中没有写入的权限(ISAPI_Rewrite要写入一个httpd.parse.errors文件)。

基本上就是这个问题了,如果是启动进程池的用户不是IIS_WPG组的,请修改成相应的用户有足够的权限。34这两个问题可能经常有朋友会遇到,ISAPI_Rewrite安装好了,只有在ISAPI_Rewrite的安装目录的httpd.ini起作用,对于Web站点根目录的站点无效。其实就是IIS_WPG组对站点目录没有读取的权限,ISAPI_Rewrite是用IIS_WPG组的用户执行的。

]]>
http://www.miaoqiyuan.cn/p/isapi-rewrite-err/feed 0