一个显示器接两个主机|一个显示原代码的asp程序

更新时间:2017-08-26 来源:服务器 点击:

【www.hzclsc.cn--服务器】












我们都知道asp这一类的服务器端处理的程序,其好处之一就是只向客户端输出
标准的Html流。因此可以起到向客户隐藏细节的作用。也就是说当我们在浏览器中
键入asp程序的网址后只能看见标准的Html文件,而不能看见asp的内容。但有时,
例如在一个asp的教学站点,我们有必要显示asp文件的内容,或者你愿意将你的原
代码与人享,通过一个程序将代码显示出来。
下面是我编写的一个asp程序,view_code.asp,它提供两种提交方式:一种是用
表格提交,即你知道了该源文件的物理地址(类似于:c:\asp_source\test.asp的
形式)。一种是采用get方式提交(类似于:
点击此处查看原代码)。另外它还支持两种cgi脚本,一种是asp,一种是php。

代码段:
<%
on error resume next
'忽略程序执行中的错误,在程序的最后统一处理。
%>
<%
function rt_min(num1,num2)
'该子程序用于返回两数中不等于零的最小数。
if num1=0 and num2=0 then
rt_min=-1
elseif num1=0 then
rt_min=num2
elseif num2=0 then
rt_min=num1
elseif num1<num2 then
rt_min=num1
else
rt_min=num2
end if
end function
%>
<%
function line_check(strline,cgi_type)
'该子程序用于检查输入段中是否包含有"<%、%>、<script或dim cgi_flag
if cgi_type="php" then
cgi_flag="?"
else
cgi_flag="%"
end if
'定义的cgi_flag用于代表php和asp的不同标识符
line_check=0
itemp=0
ipos=instr(strline,"<"&cgi_flag)
if rt_min(ipos,itemp)=ipos then
itemp=ipos
line_check=1
end if
ipos=instr(strline,cgi_flag&">")
if rt_min(ipos,itemp)=ipos then
itemp=ipos
line_check=2
end if
ipos=instr(1,strline,"<"&"script",1)
if rt_min(ipos,itemp)=ipos then
itemp=ipos
line_check=3
end if
ipos=instr(1,strline,"<"&"/script",1)
if rt_min(ipos,itemp)=ipos then
itemp=ipos
line_check=4
end if
end function
%>
<%
sub printhtml(strline)
'该子过程用于打印不含有上述四种特殊标记的行
ispace=len(strline)-len(ltrim(strline))
i=1
while(mid(strline,i,1))=chr(9)
ispace=ispace+5
i=i+1
wend
'统计空白的数量
if ispace>0 then
for i=1 to ispace
response.write("&nbsp;")
next
end if
ipos=instr(strline,"<")
if ipos then
response.write(left(strline,ipos-1))
response.write("&lt;")
'用&lt;来替代<,使浏览器不解释<>中的标记
strline=right(strline,len(strline)-ipos)
call printhtml(strline)
'自调用,直到没有<的出现
else
response.write(strline)
end if
end sub
%>
<%
sub printline(strline,iflag,cgi_type)
'该自过程用于根据line_check的返回值分别处理
dim cgi_flag
if cgi_type="php" then
cgi_flag="?"
else
cgi_flag="%"
end if
select case iflag
case 0
call printhtml(strline)
case 1
ipos=instr(strline,"<"&cgi_flag)
call printhtml(left(strline,ipos-1))
response.write("")
response.write("&lt;"&cgi_flag)
strline=right(strline,len(strline)-ipos-1)
call printline(strline,line_check(strline,cgi_type),cgi_type)
'自调用,直到没有四种特殊标记的出现
case 2
ipos=instr(strline,cgi_flag&">")
call printhtml(left(strline,ipos-1))
response.write(cgi_flag&"&gt;")
response.write("")
strline=right(strline,len(strline)-ipos-1)
call printline(strline,line_check(strline,cgi_type),cgi_type)
case 3
ipos=instr(1,strline,"<"&"script",1)
call printhtml(left(strline,ipos-1))
response.write("")
response.write("&lt;"&"script")
strline=right(strline,len(strline)-ipos-6)
call printline(strline,line_check(strline.cgi_type),cgi_type)
case 4
ipos=instr(1,strline,"<"&" script="">",1)
call printhtml(left(strline,ipos-1))
response.write("lt;"&"/script"&"&gt;")
response.write(" ")
strline=right(strline,len(strline)-ipos-8)
call printline(strline,line_check(strline,cgi_type),cgi_type)
case else
response.write("error")
end select
end sub
%>

view cgi_code(.asp or .php)




请输入路径:
请选择类型:aspphp


<%
if vartype(request.servervariables("HTTP_REFERER")) then
'判断该页面是否是由其他的页面申请提交,若用户是直接在浏览器中输入地址
而来的,则HTTP_REFERER环境变量应该没有被初始化
if request.servervariables("REQUEST_METHOD")="POST" then
code_path=request.form("code_path")
cgi_type=request.form("cgi_type")
response.write("下面的代码来自表格的提交:"&"
")
response.write("路径为:"&code_path&"
")
elseif request.servervariables("REQUEST_METHOD")="GET" then
code_path=request.querystring("code_path")
cgi_type=request.querystring("cgi_type")
response.write("下面的代码来自"&code_path&"的提交:"&"
")
response.write("路径为:"&code_path&"
")
end if
'根据提交方式的不同显示不同的提示
set fileobject=server.createobject("Scripting.FileSystemObject")
if fileobject.fileexists(code_path) then
'检查要打开的文件是否存在
set stream=fileobject.opentextfile(code_path,1,false,0)
while not stream.atendofstream
stroutput=stream.readline
call printline(stroutput,line_check(stroutput,cgi_type),cgi_type)
'将该文件的每一行都分别交给printline来处理
response.write("
")
wend
set stream=nothing
else
response.write("不能打开文件"&"
")
end if
end if
%>


<%
'下面的代码为统一的错误处理段,它根据程序运行时产生的错误代码来分别处理
if err.number<>0 then
response.write("error"&"
")
response.write("错误代码:"&err.number&"
")
response.write("错误描述:"&err.description)
end if
%>

最后,我在给出一个引用该程序的测试页面

显示代码的测试页面




点击此处查看该页的源码

本文来源:http://www.hzclsc.cn/ruanjianzixun/1482.html

为您推荐

[军团召唤]军团1944服务器指令控制台代码一览 军团1944作弊码有哪些

玩家在军团1944的服务器中可以使用一些指令来帮助游戏进行的更加方便,例如更换地图、更换队伍等。下面就为大家带来军团1944服务器指令控制台代码一览,一起来看看吧。军团1944服务器指令控制台代码一览角色扮演

2020-12-20 07:04:16   小小军团   疯狂的军团  

【龙珠战士z连不上服务器怎么设置】龙珠战士z连不上服务器怎么解决 连接服务器失败解决方法

龙珠战士z连不上服务器怎么解决?不少玩家朋友们在进入游戏后会出现连不上服务器的问题,导致无法正常的游玩,下面我们就来介绍一下龙珠战士z连接服务器失败解决方法,希望对各位有所参考。龙珠战士z连接服务器失动作射击

2020-12-19 23:04:37  

【腐蚀怎么读】腐蚀怎么联机 腐蚀搭建服务器图文教程

腐蚀是一款近期即将上架的爆款游戏,很多玩家都想组队来进行游戏。那么游戏如何联机呢?下面为大家带来腐蚀搭建服务器图文教程,希望能帮到大家。腐蚀搭建服务器图文教程Steam游戏后台服务器管理程序下载但凡是角色扮演

2020-12-19 17:04:38   铜腐蚀怎么处理   腐蚀怎么做好吃  

铁路大亨4|铁路大亨2怎么联机 铁路大亨2联机教程

铁路大亨2是一款运输策略类型的游戏,玩家该怎么在游戏中和好友进行联机游戏呢?下面就来分享一下铁路大亨2联机教程。铁路大亨2联机教程进入游戏,点多人游戏,TCP IP做主机就点新建,然后设定服务器名字(策略与战棋

2020-12-19 11:04:43   铁路大亨2秘籍   铁路大亨手机版  

我的世界服务器重启不了怎么办啊_我的世界服务器重启不了怎么办 我的世界服务器重启方法

我的世界服务器重启不了怎么办 我的世界服务器重启方法时间:2018 1 16 16:48:16来源:www pc6 com作者:佚名我要评论我的世界联机游戏中,许多玩家无法重启服务器,这种情况该怎么办

2020-12-17 07:04:32