CheckReferer Function:
Validate referer URLs.
Description:
CheckReferer Function will make sure that the URL that has referred your ASP page, is in your list of allowed URL's. This is useful for Form submission, so you can ensure that only YOUR form scripts are the ones posting to your asp scripts, no hackers.
Syntax:
bool = CheckReferer(ValidReferers)
Details:
Argument: ValidReferers: one or a list of valid referer addresses separated by comma and without http:// or /
Example:
<%
If CheckReferer("www.livio.net,www.lasp.net") Then '--- the URL is ok - do rest of processing Else '--- referring url is bad. Spit out an error message End If
%>
ASP Source Code:
<%
Function CheckReferer(ValidReferers) dim arURLs, tmpCount, boolValidURL dim strURL, nIndex If InStr(ValidReferers, ",") > 0 Then arURLs = Split(ValidReferers, ",") End if boolValidURL = False strURL = Request.ServerVariables("HTTP_REFERER") If LCase(Left(strURL,7)) = "http://" Then strURL = Mid(strURL,8) End if If LCase(Left(strURL,8)) = "https://" Then strURL = Mid(strURL,9) End if nIndex = InStr( strURL, "/") If nIndex > 0 Then strURL = Left(strURL,nIndex-1) End if If IsArray(arUrls) Then For tmpCount = 0 To UBound(arURLs) If strURL = arURLs(tmpCount) Then boolValidURL = True End if Next Else If strURL = ValidReferers Then boolValidURL = True End if End if CheckReferer = boolValidURL End Function
%>
|