How to create a [Reusable] Function in [ASP Classic]
Creating a reusable function lets you use it anywhere in your code project. I've been using this function for many years to help protect against [XSS injections] and have just used it in everything.
Copy the code below, copy and paste it into an empty page, and save it as Decoding.asp. Encoding = Change the original characters. Decoding = Change back to original characters.
<%
' Encode (Change Characters)
Function Encoding(strEncoding) ' Name to URL.'
strEncoding = Replace(strEncoding,"}",")")
strEncoding = Replace(strEncoding,"{","(")
strEncoding = Replace(strEncoding," ","_")
Encoding = strEncoding
End Function
' Decode (Change Characters back to their original Characters.)
Function Decoding(strEncoding) ' Name to URL '
strEncoding = Replace(strEncoding,")","}")
strEncoding = Replace(strEncoding,"(","{")
strEncoding = Replace(strEncoding,"_"," ")
Decoding = strEncoding
End Function
%>
To reuse this function, add an INCLUDE FILE to all pages on which you want to use the function.