Common ASP functions when doing Web pages

Source: Internet
Author: User
Tags chr end functions string split sql injection strfind variable

'----------------------------------------------------------------------
' function function: Masking HTML code
' Parameters: Strinput user input information
'----------------------------------------------------------------------
function Funinput (strinput)
If not IsNull (STR) Then
Strinput=replace (Strinput, "<", "<")
Strinput=replace (Strinput, ">", ">")
Strinput=replace (STRINPUT,CHR (32), "")
Strinput=replace (STRINPUT,CHR (34), "" ")
Strinput=replace (STRINPUT,CHR (39), "'")
Strinput=replace (STRINPUT,CHR (13), "")
Funinput=strinput
End If
End Function

'----------------------------------------------------------------------
' function function: Prevent SQL injection
' Parameter: strvalue data submitted by user
' Blotype data type
' parameter value: true numeric data
' False-character data
'----------------------------------------------------------------------
function Funsql (strvalue,blotype)
If Blotype Then
If IsNumeric (strvalue) Then
FUNSQL=CLNG (strvalue)
Else
Strvalue=0
End If
Else
If not IsNull (strvalue) Then
Strvalue=lcase (strvalue)
Strvalue=replace (strvalue, "'", "" ")
Strvalue=replace (strvalue, "select", "")
Strvalue=replace (strvalue, "Update", "")
Strvalue=replace (strvalue, INSERT, "")
Strvalue=replace (strvalue, "delete", "")
Strvalue=replace (strvalue, ";", "")
Strvalue=replace (strvalue, "", "")
Strvalue=replace (STRVALUE,CHR (255), "")
Strvalue=replace (strvalue, "*", "")
Strvalue=replace (strvalue, "%", "")
End If
End If
Funsql=strvalue
End Function

'--------------------------------------------------------------------------
' Function function: Common type conversions
' Parameter: _type data type
' _value data
' parameter value: _type 1: Convert to numeric data
' _type 2: converting to character data
' _type 3: Converting to Boolean data
'--------------------------------------------------------------------------
function Funswitch (value_,type_)
On Error Resume Next
Select Case Type_
Case 1
If IsNumeric (Value_) Then
If not IsNull (Value_) Then
FUNSWITCH=CLNG (Value_)
Else
Funswitch=0
End If
Else
Funswitch=0
End If
Case 2
If not IsNull (Value_) Then
Funswitch=cstr (Value_)
Else
Funswitch= ""
End If
Case 3
If not IsNull (Value_) and IsNumeric (Value_) Then
Funswitch=cbool (Value_)
Else
Funswitch=false
End If
Case Else
Response.Redirect ("error.asp?err= Please specify the type of data to be conveyed in Funswitch!") ")
End Select
If Err.number<>0 Then
Response.Redirect ("error.asp?err= data conversion generates an unknown error!") ")
Err.Clear
End If
End Function
''----------------------------------------------------------------------
' function function: Verify whether the data is from an external
' Parameters: None
'----------------------------------------------------------------------
function Checkfrom ()
Server_v1=cstr (Request.ServerVariables ("Http_referer"))
Server_v2=cstr (Request.ServerVariables ("SERVER_NAME"))
If Mid (Server_v1,8,len (SERVER_V2)) <>server_v2 Then
Checkfrom=true
Else
Checkfrom=false
End If
End Function

''----------------------------------------------------------------------
' function function: JS prompt box
' Parameter: strURL: Click to return to the page address after the confirmation
' StrMSG: Message for dialog box

'----------------------------------------------------------------------
Function funmsg (strurl,strmsg)
Response.Write "<script language= ' JavaScript ' >" &_
vbcrlf& "alert (" "&StrMSG&" ""); " &_
vbcrlf& "window.location=" "" &StrURL& "" ";" &_
vbcrlf& "</script>"
End Function

'--------------------------------------------------------------------------
' Function function: Universal paging
' Parameters: Intpagecount Total Pages
' Intmypage current page
' Intrecordcount Total Records
' Intpagesize the number of records displayed per page
'--------------------------------------------------------------------------
function Funpage (intpagecount,intmypage,intrecordcount,intpagesize)
' On Error Resume Next
Dim intfor,intlist,intlist_b
Dim query, a, X, temp
Action = "http://" & Request.ServerVariables ("Http_host") & Request.ServerVariables ("Script_name")
query = Split (Request.ServerVariables ("query_string"), "&")
For each x in query
A = Split (x, "=")
If StrComp (A (0), "page", vbTextCompare) <> 0 Then
Temp = temp & A (0) & "=" & A (1) & "&"
End If
Next
If Intmypage>1 Then
Funpage=funpage & "<a href= '" &action& "?" &temp& "page=1 ' title= ' front page ' class= ' no ' ><font face= ' webdings ' >9</font></a>"
funpage=funpage& "<a href=" "&action&"? &temp& "page=" &intmypage-1 & "' title= ' prev ' class= ' no ' ><font face= ' webdings ' >7</font> </a> "
Else
Funpage=funpage & "<font face= ' webdings ' >9</font>"
funpage=funpage& "<font face= ' webdings ' >7</font>"
End If
If Intlist<>0 Then
If cintmypage= Intlist Then
Intlist=intlist+5
End If
Else
Intlist=intmypage+5
End If
If Intlist-9<1 Then
Intlist_b=1
Else
Intlist_b=intlist-9
End If
For Intfor=intlist_b to Intlist
If Intfor<=intpagecount Then
If Intfor=intmypage then '-------make the current page text red and not clickable
Funpage =funpage & strmode& "<font color= ' #FF0000 ' ><b>" & intfor & "</b></font> "
Else
Funpage=funpage & Strmode & "<a href=" &action& "?" &temp& "page=" & Intfor & "' class= ' no ' >" & intfor & "</a>"
End If
End If
Strmode= "<font color= ' #BBBBBB ' >|</font>"
Next
If Intmypage<intpagecount Then
funpage=funpage& "<a href=" "&action&"? &temp& "page=" & intmypage+1 & "' title= ' after page ' class= ' no ' ><font face= ' webdings ' >8</font> </a> "
Funpage=funpage & "<a href= '" &action& "?" &temp& "page=" & Intpagecount & "' title= ' last page ' class= ' no ' ><font face= ' webdings ' >:</font ></a> "
Else
funpage=funpage& "<font face= ' webdings ' >8</font>"
Funpage=funpage & "<font face= ' webdings ' >:</font></a>"
End If
funpage= "<table width= ' 100% ' border= ' 0 ' cellspacing= ' 0 ' cellpadding= ' 0 ' ><tr>" &_
vbcrlf& "<td width= ' 40% ' style=font:14px> current Page" &Intmypage& "page" &Intpagesize& "Strip/Page Total & intpagecount& "page/" &Intrecordcount& "Record </td>" &_
vbcrlf& "<td width= ' 60% ' align= ' right ' >" &_
vbcrlf& "<table width= ' 360 ' border= ' 0 ' cellspacing= ' 0 ' cellpadding= ' 0 ' ><tr>" &_
vbcrlf& "<td align= ' right ' style=font:14px>" &funpage& "</td>" &_
vbcrlf& "</tr></table></td></tr>" &_
vbcrlf& "</table>"
If Err.number<>0 Then
Err.Clear
Response.Redirect ("error.asp?err= paging function error, contact Administrator!|")
End If
End Function
'***************************************************
' Function name: Highlight
' function: Search for keywords to display in highlighted colors
' Parameter strtext is the string or variable that contains the strings or variables to be highlighted
' Strfind is a string or variable to be highlighted,
' Strbefore is highlighted by the HTML code prefix such as: <font color=red>
' Strafter is highlighted by the suffix of the HTML code:</font>
'*****************************************************
Function Highlight (StrText, Strfind, Strbefore, Strafter)
Dim NPOs
Dim Nlen
Dim Nlenall

Nlen = Len (strfind)
Nlenall = Nlen + len (strbefore) + len (strafter) + 1
Highlight = StrText
If nlen > 0 and Len (highlight) > 0 Then
NPOs = INSTR (1, highlight, Strfind, 1)
Do While NPOs > 0
Highlight = Left (Highlight, nPos-1) & _
Strbefore & Mid (Highlight, NPOs, Nlen) & Strafter & _
Mid (Highlight, NPOs + nlen)
NPOs = InStr (NPOs + nlenall, highlight, Strfind, 1)
Loop
End If
End Function



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.