Use of HTTP_REFERER in Global.asa

P

Prabhat

Hello,

I have the below requirement.

When ever my website is opened by any link: say clicked from the google
search result or a link from other website:

Then I should able to know the referrer URL. How Do I get that?

I know about Request.ServerVariables("HTTP_REFERER"). So I used this in
"global.asa" file in "Session_OnStart" event like this:

Sub Session_OnStart
Session("ReferralURL") = Request.ServerVariables("HTTP_REFERER")
End Sub

Sub Session_OnEnd
Session("ReferralURL") = ""
End Sub

So that I can use the session variable any where in my website, because the
HTTP_REFERER will give the URL of the last webpage.

But this seems to not working.

Please help.

Thanks
Prabhat
 
E

Evertjan.

Prabhat wrote on 01 sep 2005 in microsoft.public.inetserver.asp.general:
Hello,

I have the below requirement.

When ever my website is opened by any link: say clicked from the
google search result or a link from other website:

Then I should able to know the referrer URL. How Do I get that?

I know about Request.ServerVariables("HTTP_REFERER"). So I used this
in "global.asa" file in "Session_OnStart" event like this:

Sub Session_OnStart
Session("ReferralURL") = Request.ServerVariables("HTTP_REFERER")
End Sub

Seting a session variable here will not work, IMHO.
Sub Session_OnEnd
Session("ReferralURL") = ""
End Sub

Clearing a session variable here has no effect, since all session
variables die with the end of a session anyway.
So that I can use the session variable any where in my website,
because the HTTP_REFERER will give the URL of the last webpage.

No, in your case it would [but doesn't] give only the URL of referral
site when opening the session.

Better put this file as an include
<!--#include virtual ="/test/myInclude.asp"-->
on all your pages:

/test/myInclude.asp:
<%
if Session("started") = "" then
Session("ReferralURL") = Request.ServerVariables("HTTP_REFERER")
Session("started") = "yes!"
end if
%>
 
P

Prabhat

Hi Evertjan, Thanks for reply.

You mean to say if I put the Session("ReferralURL") =
Request.ServerVariables("HTTP_REFERER") in Session_OnStart it will not work.
I have also tested that and it is not working. Can you please explain why?
Because as per my knowledge the Session_OnStart event will start for each
session.

As per your suggestion I will create one .asp file with the sample code and
include the file in all pages.

Can you suggest an easy method so that I need not to modify all the pages to
include the new file?

I think your logic says that if the Session Variable "started" is empty then
only assign the Session Variable with the Referral URL else no.

But dont you think I should also crear these variables on Session_OnEnd
event? Please suggest.

Thanks
Prabhat


Evertjan. said:
Prabhat wrote on 01 sep 2005 in microsoft.public.inetserver.asp.general:
Hello,

I have the below requirement.

When ever my website is opened by any link: say clicked from the
google search result or a link from other website:

Then I should able to know the referrer URL. How Do I get that?

I know about Request.ServerVariables("HTTP_REFERER"). So I used this
in "global.asa" file in "Session_OnStart" event like this:

Sub Session_OnStart
Session("ReferralURL") = Request.ServerVariables("HTTP_REFERER")
End Sub

Seting a session variable here will not work, IMHO.
Sub Session_OnEnd
Session("ReferralURL") = ""
End Sub

Clearing a session variable here has no effect, since all session
variables die with the end of a session anyway.
So that I can use the session variable any where in my website,
because the HTTP_REFERER will give the URL of the last webpage.

No, in your case it would [but doesn't] give only the URL of referral
site when opening the session.

Better put this file as an include
<!--#include virtual ="/test/myInclude.asp"-->
on all your pages:

/test/myInclude.asp:
<%
if Session("started") = "" then
Session("ReferralURL") = Request.ServerVariables("HTTP_REFERER")
Session("started") = "yes!"
end if
%>
 
E

Evertjan.

Prabhat wrote on 01 sep 2005 in microsoft.public.inetserver.asp.general:
Evertjan. said:
Prabhat wrote on 01 sep 2005 in
I know about Request.ServerVariables("HTTP_REFERER"). So I used
this in "global.asa" file in "Session_OnStart" event like this:

Sub Session_OnStart
Session("ReferralURL") = Request.ServerVariables("HTTP_REFERER")
End Sub

Seting a session variable here will not work, IMHO.
Sub Session_OnEnd
Session("ReferralURL") = ""
End Sub

Clearing a session variable here has no effect, since all session
variables die with the end of a session anyway.
So that I can use the session variable any where in my website,
because the HTTP_REFERER will give the URL of the last webpage.

No, in your case it would [but doesn't] give only the URL of referral
site when opening the session.

Better put this file as an include
<!--#include virtual ="/test/myInclude.asp"-->
on all your pages:

/test/myInclude.asp:
<%
if Session("started") = "" then
Session("ReferralURL") = Request.ServerVariables("HTTP_REFERER")
Session("started") = "yes!"
end if
%>

[please do not toppost on usenet]
You mean to say if I put the Session("ReferralURL") =
Request.ServerVariables("HTTP_REFERER") in Session_OnStart it will not
work. I have also tested that and it is not working. Can you please
explain why? Because as per my knowledge the Session_OnStart event
will start for each session.

It is als per specification. Only certein objects are available
in global.asa, I think
As per your suggestion I will create one .asp file with the sample
code and include the file in all pages.

Can you suggest an easy method so that I need not to modify all the
pages to include the new file?

No. Unless you mean local programming in C++ or VB etc..
I think your logic says that if the Session Variable "started" is
empty then only assign the Session Variable with the Referral URL else
no.

Otherwise Session("ReferralURL") would be filled with each referring
local page.
But dont you think I should also crear these variables on
Session_OnEnd event? Please suggest.

As I said, no.

1 Session variables without sessions are deleted automaticly.

2 Session_OnEnd firing is unrelyable.

3 Sessions do not end, when the user "leaves" [sloppy defined] the site,
but only when the session times out or with commands like session.abandon
or with the server closing down/restarting.
 
P

Prabhat

Evertjan. said:
Prabhat wrote on 01 sep 2005 in microsoft.public.inetserver.asp.general:
Evertjan. said:
Prabhat wrote on 01 sep 2005 in
I know about Request.ServerVariables("HTTP_REFERER"). So I used
this in "global.asa" file in "Session_OnStart" event like this:

Sub Session_OnStart
Session("ReferralURL") = Request.ServerVariables("HTTP_REFERER")
End Sub

Seting a session variable here will not work, IMHO.

Sub Session_OnEnd
Session("ReferralURL") = ""
End Sub

Clearing a session variable here has no effect, since all session
variables die with the end of a session anyway.

So that I can use the session variable any where in my website,
because the HTTP_REFERER will give the URL of the last webpage.

No, in your case it would [but doesn't] give only the URL of referral
site when opening the session.

Better put this file as an include
<!--#include virtual ="/test/myInclude.asp"-->
on all your pages:

/test/myInclude.asp:
<%
if Session("started") = "" then
Session("ReferralURL") = Request.ServerVariables("HTTP_REFERER")
Session("started") = "yes!"
end if
%>

[please do not toppost on usenet]
You mean to say if I put the Session("ReferralURL") =
Request.ServerVariables("HTTP_REFERER") in Session_OnStart it will not
work. I have also tested that and it is not working. Can you please
explain why? Because as per my knowledge the Session_OnStart event
will start for each session.

It is als per specification. Only certein objects are available
in global.asa, I think
As per your suggestion I will create one .asp file with the sample
code and include the file in all pages.

Can you suggest an easy method so that I need not to modify all the
pages to include the new file?

No. Unless you mean local programming in C++ or VB etc..
I think your logic says that if the Session Variable "started" is
empty then only assign the Session Variable with the Referral URL else
no.

Otherwise Session("ReferralURL") would be filled with each referring
local page.
But dont you think I should also crear these variables on
Session_OnEnd event? Please suggest.

As I said, no.

1 Session variables without sessions are deleted automaticly.

2 Session_OnEnd firing is unrelyable.

3 Sessions do not end, when the user "leaves" [sloppy defined] the site,
but only when the session times out or with commands like session.abandon
or with the server closing down/restarting.

Hi Evertjan,

Thanks for the reply. Now I understodd the concept. Thanks for the post.

Prabaht
 
A

Aaron Bertrand [SQL Server MVP]

Does anybody see what's wrong with bottom-posting here? Just curious if
it's only me that is irritated to scroll through 90 lines of re-hashed
garbage to see "thank you."





Prabhat said:
Evertjan. said:
Prabhat wrote on 01 sep 2005 in microsoft.public.inetserver.asp.general:
....
this in "global.asa" file in "Session_OnStart" event like this:

Sub Session_OnStart
Session("ReferralURL") = Request.ServerVariables("HTTP_REFERER")
End Sub

Seting a session variable here will not work, IMHO.

Sub Session_OnEnd
Session("ReferralURL") = ""
End Sub

Clearing a session variable here has no effect, since all session
variables die with the end of a session anyway.

So that I can use the session variable any where in my website,
because the HTTP_REFERER will give the URL of the last webpage.

No, in your case it would [but doesn't] give only the URL of referral
site when opening the session.

Better put this file as an include
<!--#include virtual ="/test/myInclude.asp"-->
on all your pages:

/test/myInclude.asp:
<%
if Session("started") = "" then
Session("ReferralURL") = Request.ServerVariables("HTTP_REFERER")
Session("started") = "yes!"
end if
%>

[please do not toppost on usenet]
You mean to say if I put the Session("ReferralURL") =
Request.ServerVariables("HTTP_REFERER") in Session_OnStart it will not
work. I have also tested that and it is not working. Can you please
explain why? Because as per my knowledge the Session_OnStart event
will start for each session.

It is als per specification. Only certein objects are available
in global.asa, I think
As per your suggestion I will create one .asp file with the sample
code and include the file in all pages.

Can you suggest an easy method so that I need not to modify all the
pages to include the new file?

No. Unless you mean local programming in C++ or VB etc..
I think your logic says that if the Session Variable "started" is
empty then only assign the Session Variable with the Referral URL else
no.

Otherwise Session("ReferralURL") would be filled with each referring
local page.
But dont you think I should also crear these variables on
Session_OnEnd event? Please suggest.

As I said, no.

1 Session variables without sessions are deleted automaticly.

2 Session_OnEnd firing is unrelyable.

3 Sessions do not end, when the user "leaves" [sloppy defined] the site,
but only when the session times out or with commands like session.abandon
or with the server closing down/restarting.

Hi Evertjan,

Thanks for the reply. Now I understodd the concept. Thanks for the post.

Prabaht
 
E

Evertjan.

Aaron Bertrand [SQL Server MVP] wrote on 01 sep 2005 in
microsoft.public.inetserver.asp.general:
Does anybody see what's wrong with bottom-posting here? Just curious if
it's only me that is irritated to scroll through 90 lines of re-hashed
garbage to see "thank you."

Bottom-posting is not the alternative of top-posting, Aaron.
Re-posting garbage is always a bad habit.
Sparse inter-posting is the best.
Top-posting should be discouraged at all times on usenet.

I am sorry that you ar so easily irritated,
and thereby forgetting what 30 years of
usenet experience brought us:
Netiquette.
 
D

Danny@Kendal

Aaron Bertrand said:
Prabhat said:
Evertjan. said:
Prabhat wrote on 01 sep 2005 in microsoft.public.inetserver.asp.general:
Prabhat wrote on 01 sep 2005 in
...
this in "global.asa" file in "Session_OnStart" event like this:

Sub Session_OnStart
Session("ReferralURL") = Request.ServerVariables("HTTP_REFERER")
End Sub

Seting a session variable here will not work, IMHO.

Sub Session_OnEnd
Session("ReferralURL") = ""
End Sub

Clearing a session variable here has no effect, since all session
variables die with the end of a session anyway.

So that I can use the session variable any where in my website,
because the HTTP_REFERER will give the URL of the last webpage.

No, in your case it would [but doesn't] give only the URL of referral
site when opening the session.

Better put this file as an include
<!--#include virtual ="/test/myInclude.asp"-->
on all your pages:

/test/myInclude.asp:
<%
if Session("started") = "" then
Session("ReferralURL") = Request.ServerVariables("HTTP_REFERER")
Session("started") = "yes!"
end if
%>

[please do not toppost on usenet]

You mean to say if I put the Session("ReferralURL") =
Request.ServerVariables("HTTP_REFERER") in Session_OnStart it will not
work. I have also tested that and it is not working. Can you please
explain why? Because as per my knowledge the Session_OnStart event
will start for each session.

It is als per specification. Only certein objects are available
in global.asa, I think

As per your suggestion I will create one .asp file with the sample
code and include the file in all pages.

Can you suggest an easy method so that I need not to modify all the
pages to include the new file?

No. Unless you mean local programming in C++ or VB etc..

I think your logic says that if the Session Variable "started" is
empty then only assign the Session Variable with the Referral URL else
no.

Otherwise Session("ReferralURL") would be filled with each referring
local page.

But dont you think I should also crear these variables on
Session_OnEnd event? Please suggest.

As I said, no.

1 Session variables without sessions are deleted automaticly.

2 Session_OnEnd firing is unrelyable.

3 Sessions do not end, when the user "leaves" [sloppy defined] the site,
but only when the session times out or with commands like
session.abandon
or with the server closing down/restarting.

Hi Evertjan,

Thanks for the reply. Now I understodd the concept. Thanks for the post.

[repositioned from top-posted reply]
Does anybody see what's wrong with bottom-posting here? Just curious if
it's only me that is irritated to scroll through 90 lines of re-hashed
garbage to see "thank you."

Nowhere near as irritating as someone who breaks the flow of a thread.
 
M

McKirahan

Aaron Bertrand said:
Does anybody see what's wrong with bottom-posting here? Just curious if
it's only me that is irritated to scroll through 90 lines of re-hashed
garbage to see "thank you."

[snip]


Why should I not top-post?
http://www.html-faq.com/etiquette/?toppost

"One reason why top-posting is so disliked is that those who do it very
rarely bother to snip any of the preceding post(s) - they leave masses of
quoted text trailing underneath their (frequently very brief) reply."


Usenet Basics
http://mugsy.org/asa_faq/getting_along/usenet.shtml

2. Replying and Quoting

There are many arguments about how to reply to a post on Usenet. There are
standard conventions and on a.s.a we have our preferred styles, briefly
described below.

a. Should I leave in the post I'm replying to, or delete it?

Snip (delete) the parts of a post you're not responding to directly, but
leave in some parts so people know what you're referring to.
 
E

Evertjan.

Dave Anderson wrote on 01 sep 2005 in
microsoft.public.inetserver.asp.general:
This would appear to contradict that claim:

"All the built-in objects (Application Object, ObjectContext
Object, Request Object, Response Object, Server Object, and
Session Object) are available and can be referenced in the
Session_OnStart event script."

http://msdn.microsoft.com/library/en-us/iissdk/html/3b6d0cc8-361e-418b-
99e0-b0f289198c16.asp

Thank you, Dave.

I thought I had heard otherwise, but clearly I am wrong.

What do you think could be Prabhat's problem then?
 
A

Aaron Bertrand [SQL Server MVP]

Bottom-posting is not the alternative of top-posting, Aaron.
Re-posting garbage is always a bad habit.

You did it in this very thread.
Top-posting should be discouraged at all times on usenet.

WHY? Because you say so? Because one guy somewhere stated that he doesn't
like it? Blow it out your shorts.
I am sorry that you ar so easily irritated,

No, I was just showing an example where your constant "do not top-post on
usenet" leads to an even less desirable behavior.
and thereby forgetting what 30 years of
usenet experience brought us:
Netiquette.

So sorry grand master, you know all and I am an idiot. Bottom-post away.
 
A

Aaron Bertrand [SQL Server MVP]

Evertjan gets bent out of shape every time anyone top-posts. I do sometimes
because it's easy, and sometimes because it puts the most relevant content
"above the fold" -- e.g. less scrolling and scanning. More often, I
intersperse my comments where they're relevant, unless I'm only responding
to a single segment of the previous post (such as this example).

AFAIC, neither is a should or shouldn't thing, it is a personal preference.
Unlike Evertjan, I don't attack people who do one or the other and try to
coerce them to my point of view, and try to say that my view and
interpretation of netiquette is superior to all others. In this case, I was
highlighting it because it was a very good example of what bottom-posting
naturally leads to -- scrolling to the bottom of a 90-line message and
adding a one-liner at the end.
 
A

Aaron Bertrand [SQL Server MVP]

This is ridiculous. I don't see how this is any more likely with
top-posting than bottom-posting. This thread should serve as a prime
example of where it can happen just as easily with bottom-posting.

Evertjan has attacked me in the past for top-posting and I can not remember
any situation where it had anything to do with me carelessly leaving useless
garbage in my reply.
 
E

Evertjan.

Aaron Bertrand [SQL Server MVP] wrote on 01 sep 2005 in
microsoft.public.inetserver.asp.general:
You did it in this very thread.

What is garbage and what is not is in the eye of the beholder. ;-)
WHY? Because you say so? Because one guy somewhere stated that he
doesn't like it? Blow it out your shorts.

Why so aggressive, Aaron?

Again and again in the years I tell my meaning about preferred behavour
on usenet. I know you think differently. So be it. That does not mean I
should not tell others.
No, I was just showing an example where your constant "do not top-post
[/QUOTE]

See, you came up with the the word "irritated"!
So sorry grand master, you know all and I am an idiot. Bottom-post
away.

Thank you, Aaron, if you say so.

However, I did not advocate bottom-posting,
I politely asked not to top-post.
I don't think you are an idiot,
I think you are one of the mainstays of this NG.
 
E

Evertjan.

Aaron Bertrand [SQL Server MVP] wrote on 01 sep 2005 in
microsoft.public.inetserver.asp.general:
Evertjan has attacked me in the past for top-posting and I can not
remember any situation where it had anything to do with me carelessly
leaving useless garbage in my reply.

See, still you are irritated, Aaron.

Please don't be.

As far as I can remember,
I never attacked anyone,
unless you call a polite

"[please do not toppost on usenet]"

an attack.
 
P

Prabhat

This would appear to contradict that claim:
"All the built-in objects (Application Object, ObjectContext
Object, Request Object, Response Object, Server Object, and
Session Object) are available and can be referenced in the
Session_OnStart event script."

http://msdn.microsoft.com/library/en-us/iissdk/html/3b6d0cc8-361e-418b-99e0-
b0f289198c16.asp
Hi Dave,

Can you please lookinto my problem in the 1st post in this thread. Can you
please put some light on that or can you suggest me how can i do that?

Thanks
Prabhat
 
E

Evertjan.

Prabhat wrote on 01 sep 2005 in microsoft.public.inetserver.asp.general:
Hi,

can you now suggest any thing?

Yes, testing!

Set a session variable with global.asa onstart,
and try to tead it on a page.
 
P

Prabhat

Thank you, Dave.
I thought I had heard otherwise, but clearly I am wrong.

What do you think could be Prabhat's problem then?

Hi,

can you now suggest any thing?

Thanks
Prabhat
 
A

Aaron Bertrand [SQL Server MVP]

HTTP_REFERER is not always available (see http://www.aspfaq.com/2169). This
is, however, not one of those cases. This technique worked fine for me, as
long as the click actualy started a new session. I just did this on my own
box, with an HTML file I called from http://localhost/file.htm, with a link
to http://my_machine_name/file.asp, where global.asa in the root set a
session variable just like you do below, and file.asp outputs the session
variable. Worked flawlessly, as long as I started from scratch (e.g. closed
the browser).

If you are on your site, and then go to Google, and click on a link that
takes you to your site, session_onstart() won't fire because you still have
the old session.

Don't try to set the string to an empty string in session_onEnd. There is
no point. If session_onEnd is actually being called, then your variables
are blown away for you. But more often than not, it will not be called
(see http://www.aspfaq.com/2078).

My guess is that session variables are not working
(http://www.aspfaq.com/2157) or global.asa is not being called at all (see
http://www.aspfaq.com/2076). To isolate the problem, create a global.asa
that sets a session variable (just a constant/string, not based on
servervariables) in session_onstart. Open a new browser window, navigate to
a page that sets a different session variable, then navigate to a third page
that displays them both.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top