We help IT Professionals succeed at work.

Using Request.ServerVariables("HTTP_REFERER")

Martin Cotterill
Medium Priority
Last Modified: 2012-06-27
Hello everyone

I have a piece of code that came from EE which I sort of understand. However, I don't know how to expand on it.

The code is:

<% If Right(Request.ServerVariables("HTTP_REFERER"),24) = "20yearsTrustMessages.asp" Then

Response.Write("<div id='goBack'><a href='javascript:back()' class='goBack'>[ Return to the previous page ]</a></div>")

End If %>

It works fine if referer is '20yearsTrustMessages.asp' but we now use Recordset Paging and the extension can be followed by '?offset=...'. with the figure after the = varying (-1, 0 ,10, 20 etc).

I don't know how to change the referer to reflect '?offset=...' if it's there. I thought of using a wildcard but I don't know how to use them.

Can you help me out?
Watch Question

You probably want to use a regular expression.  I'm on my way out the door, so this is a quick hack of one.  Someone else can probably provide a better working example that will meet all the instances you want:

dim re
set re = new RegExp
re.IgnoreCase = true
re.Global = false
re.Pattern = "^.*20yearsTrustMessages.asp(\?offset=.*)?$"
if re.test(Request.ServerVariables("HTTP_REFERRER")) then
'do whatever here
end if

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.