六月婷婷综合激情-六月婷婷综合-六月婷婷在线观看-六月婷婷在线-亚洲黄色在线网站-亚洲黄色在线观看网站

明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

一個(gè)顯示原代碼的asp程序

[摘要]我們都知道asp這一類(lèi)的服務(wù)器端處理的程序,其好處之一就是只向客戶(hù)端輸出 標(biāo)準(zhǔn)的Html流。因此可以起到向客戶(hù)隱藏細(xì)節(jié)的作用。也就是說(shuō)當(dāng)我們?cè)跒g覽器中 鍵入asp程序的網(wǎng)址后只能看見(jiàn)標(biāo)準(zhǔn)的Html文件,而不能看見(jiàn)asp的內(nèi)容。但有時(shí), 例如在一個(gè)asp的教學(xué)站點(diǎn),我們有必要顯示asp文件的內(nèi)容,或...

我們都知道asp這一類(lèi)的服務(wù)器端處理的程序,其好處之一就是只向客戶(hù)端輸出
標(biāo)準(zhǔn)的Html流。因此可以起到向客戶(hù)隱藏細(xì)節(jié)的作用。也就是說(shuō)當(dāng)我們?cè)跒g覽器中
鍵入asp程序的網(wǎng)址后只能看見(jiàn)標(biāo)準(zhǔn)的Html文件,而不能看見(jiàn)asp的內(nèi)容。但有時(shí),
例如在一個(gè)asp的教學(xué)站點(diǎn),我們有必要顯示asp文件的內(nèi)容,或者你愿意將你的原
代碼與人享,通過(guò)一個(gè)程序?qū)⒋a顯示出來(lái)。
下面是我編寫(xiě)的一個(gè)asp程序,view_code.asp,它提供兩種提交方式:一種是用
表格提交,即你知道了該源文件的物理地址(類(lèi)似于:c:\asp_source\test.asp的
形式)。一種是采用get方式提交(類(lèi)似于:<a href="view_code.asp?code_path=
<%=server.mappath(request.servervariables("PATH_INFO"))%>&cgi_type=asp">
點(diǎn)擊此處查看原代碼</a>)。另外它還支持兩種cgi腳本,一種是asp,一種是php。

代碼段:
<%
on error resume next
'忽略程序執(zhí)行中的錯(cuò)誤,在程序的最后統(tǒng)一處理。
%>
<%
function rt_min(num1,num2)
'該子程序用于返回兩數(shù)中不等于零的最小數(shù)。
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或</script的特殊字符
dim cgi_flag
if cgi_type="php" then
cgi_flag="?"
else
cgi_flag="%"
end if
'定義的cgi_flag用于代表php和asp的不同標(biāo)識(shí)符
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)
'該子過(guò)程用于打印不含有上述四種特殊標(biāo)記的行
ispace=len(strline)-len(ltrim(strline))
i=1
while(mid(strline,i,1))=chr(9)
ispace=ispace+5
i=i+1
wend
'統(tǒng)計(jì)空白的數(shù)量
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;來(lái)替代<,使瀏覽器不解釋<>中的標(biāo)記
strline=right(strline,len(strline)-ipos)
call printhtml(strline)
'自調(diào)用,直到?jīng)]有<的出現(xiàn)
else
response.write(strline)
end if
end sub
%>
<%
sub printline(strline,iflag,cgi_type)
'該自過(guò)程用于根據(jù)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("<font color=#ff0000>")
response.write("&lt;"&cgi_flag)
strline=right(strline,len(strline)-ipos-1)
call printline(strline,line_check(strline,cgi_type),cgi_type)
'自調(diào)用,直到?jīng)]有四種特殊標(biāo)記的出現(xiàn)
case 2
ipos=instr(strline,cgi_flag&">")
call printhtml(left(strline,ipos-1))
response.write(cgi_flag&"&gt;")
response.write("</font>")
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("<font color=#00ff00>")
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("</font>")
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
%>
<html>
<head>
<title> view cgi_code(.asp or .php) </title>
</head>
<body>
<form action="view_code.asp" method="POST">
請(qǐng)輸入路徑:<input type=text name="code_path">
請(qǐng)選擇類(lèi)型:<select name="cgi_type">
<option value="asp">asp</option>
<option value="php">php</option>
</select>
<input type=submit>
</form>
<hr>
<%
if vartype(request.servervariables("HTTP_REFERER")) then
'判斷該頁(yè)面是否是由其他的頁(yè)面申請(qǐng)?zhí)峤�,若用�?hù)是直接在瀏覽器中輸入地址
而來(lái)的,則HTTP_REFERER環(huán)境變量應(yīng)該沒(méi)有被初始化
if request.servervariables("REQUEST_METHOD")="POST" then
code_path=request.form("code_path")
cgi_type=request.form("cgi_type")
response.write("下面的代碼來(lái)自表格的提交:"&"<br>")
response.write("路徑為:"&code_path&"<br>")
elseif request.servervariables("REQUEST_METHOD")="GET" then
code_path=request.querystring("code_path")
cgi_type=request.querystring("cgi_type")
response.write("下面的代碼來(lái)自"&code_path&"的提交:"&"<br>")
response.write("路徑為:"&code_path&"<br>")
end if
'根據(jù)提交方式的不同顯示不同的提示
set fileobject=server.createobject("Scripting.FileSystemObject")
if fileobject.fileexists(code_path) then
'檢查要打開(kāi)的文件是否存在
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來(lái)處理
response.write("<br>")
wend
set stream=nothing
else
response.write("不能打開(kāi)文件"&"<br>")
end if
end if
%>
</body>
</html>
<%
'下面的代碼為統(tǒng)一的錯(cuò)誤處理段,它根據(jù)程序運(yùn)行時(shí)產(chǎn)生的錯(cuò)誤代碼來(lái)分別處理
if err.number<>0 then
response.write("error"&"<br>")
response.write("錯(cuò)誤代碼:"&err.number&"<br>")
response.write("錯(cuò)誤描述:"&err.description)
end if
%>

最后,我在給出一個(gè)引用該程序的測(cè)試頁(yè)面
<html>
<head>
<title>顯示代碼的測(cè)試頁(yè)面</title>
</head>
<body>
<a href="view_code.asp?code_path=<%=server.mappath(request.servervariables
("PATH_INFO"))%>&cgi_type=asp">點(diǎn)擊此處查看該頁(yè)的源碼</a>
</body>
</html>(出處:熱點(diǎn)網(wǎng)絡(luò))


主站蜘蛛池模板: 日韩中文字幕精品一区在线 | 亚洲乱码一二三四区麻豆 | 三级主播| 日本视频在线观看播放免费 | 色黄网站成年女人色毛片 | 日本免费三片在线播放 | 天天综合网天天综合色不卡 | 中文字幕不卡 | 青青草国产免费久久久下载 | 亚洲狠狠| 午夜视频福利在线 | 亚洲高清视频网站 | 青草影视| 最近最新的日本中文字幕 | 人人爽天天碰天天躁夜夜躁 | 亚洲一区二区黄色 | 日韩视频第一页 | 四虎网站 | 在线免费福利 | 伊人中文字幕 | 手机在线精品视频每日更新 | 欧美一级久久 | 手机国产乱子伦精品视频 | 亚洲精品中文字幕无乱码 | 亚洲天堂一区二区 | 青青青青手机在线视频观看国产 | 揉女胸视频www网站免费观看 | 五月天丁香在线 | 三级亚洲 | 新男人皇宫亚洲男人 | 日本高清观看视频 | 日韩一区二区精品久久高清 | 伊人久久青青 | 日本成人片在线观看 | 香蕉视频导航 | 婷婷丁香久久 | 午夜在线播放免费高清观看 | 亚洲成人免费看 | 性生活国产 | 青草免费视频 | 伊人免费视频二 |