
Originally Posted by
djr33
In PHP, I believe there is another variable for just the domain.
Not for the referrer. That must be obtained by parsing the Referer header.
(something like HTTP_HOST, or something)
That is the name of an element in the $_SERVER super-global, and, like all element names beginning "HTTP_", it is the value of a HTTP header (Host, in this case).
Exactly how to implement this depends on the language used to interact with ASP.
JScript should look something like this:
Code:
var referrer = Request.ServerVariables('HTTP_REFERER'),
matches = /^[^:\/?#]+:\/\/([^\/?#]+)/.exec(referrer),
referringDomain;
if (matches) referringDomain = matches[1];
The VBScript equivalent should look something like:
Code:
Dim referrer, pattern, matches, referringDomain
Set pattern = New RegExp
referrer = Request.ServerVariables('HTTP_REFERER')
pattern.Pattern = "^[^:/?#]+://([^/?#]+)"
Set matches = pattern.Execute(referrer)
If matches.Length = 1 Then
referringDomain = matches(0).Value
End If
I can't be sure though: I can't test it and I don't even know if the Matches collection has a Length property. My reference (written by Microsoft) alludes to a single read-only property, but doesn't mention what it's called; I can only assume it's supposed to be the number of elements in the collection.
Keep in mind that the Referer header doesn't need to exist and its value can be spoofed.
Anyway, I hope that helps,
Mike
Bookmarks