Source code We all know the ASP this kind of server-side processing programs, one of the benefits is that only to the client output
The standard HTML stream. So it can play a role in hiding details from the customer. Which means that when we're in the browser
You can only see the standard HTML file when you type the ASP program's URL, but you cannot see the ASP content. But sometimes,
For example, in an ASP's teaching site, we need to display the contents of ASP files, or you are willing to put your original
Code and people, to show the code through a program.
Here is an ASP program I wrote, View_code.asp, which provides two ways to submit: one is
The form is submitted, that is, you know the physical address of the source file (similar to: C:\asp_source\test.asp's
form). One is a get-way commit (similar to: <a href= "view_code.asp?code_path=
<%=server.mappath (Request.ServerVariables ("Path_info"))%>&cgi_type=asp ">
Click here to view the original code </a>). It also supports two kinds of CGI scripts, one is ASP, one is PHP.
Code Snippets:
<%
On Error Resume Next
' Ignore errors in program execution and deal with them at the end of the program.
%>
<%
function Rt_min (num1,num2)
' The subroutine is used to return the least decimal number in two numbers that is not equal to zero.
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)
' This subroutine is used to check if the input segment contains special characters for <%,%>, <script, or </script
Dim Cgi_flag
If cgi_type= "PHP" Then
Cgi_flag= "?"
Else
cgi_flag= "%"
End If
' defined Cgi_flag used to represent different identifiers for PHP and 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)
' This child procedure is used to print lines that do not contain the four special tags
Ispace=len (strline)-len (LTrim (strline))
I=1
while (Mid (strline,i,1)) =CHR (9)
Ispace=ispace+5
I=i+1
Wend
' Number of statistic blanks
If Ispace>0 Then
For I=1 to Ispace
Response.Write ("")
Next
End If
Ipos=instr (strline, "<")
If IPOs then
Response.Write (Left (strline,ipos-1))
Response.Write ("<")
' Use < to replace the, so that the browser does not explain the tags in <>
Strline=right (Strline,len (strline)-ipos)
Call Printhtml (strline)
' Since the call, until no < appears
Else
Response.Write (strline)
End If
End Sub
%>
<%
Sub PrintLine (Strline,iflag,cgi_type)
' This process is used to handle the Line_check based on the return value of the
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 ("<" &cgi_flag)
Strline=right (Strline,len (strline)-ipos-1)
Call PrintLine (Strline,line_check (Strline,cgi_type), Cgi_type)
' Since the call, until no four special tags appear
Case 2
Ipos=instr (strline,cgi_flag& ">")
Call Printhtml (Left (strline,ipos-1))
Response.Write (cgi_flag& ">")
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 ("<" & "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" & ">")
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
%>
<title> view Cgi_code (. asp or. php) </title>
<body>
<form action= "view_code.asp" method= "POST" >
Please enter the path: <input type=text name= "Code_path" >
Please select type: <select name= "Cgi_type&qu