Getting request's source site

G

Guy Tamir

Hi all,

I was wondering how i can get the source from which the request came from.
If a user posted a link that directs to my server on facebook i'd like to know that a specific click was from facebook or twitter etc..

Thanks
 
S

Steven D'Aprano

Hi all,

I was wondering how i can get the source from which the request came
from. If a user posted a link that directs to my server on facebook i'd
like to know that a specific click was from facebook or twitter etc..

That would be the "referer" header in the HTTP request. (Note that it is
an accidental misspelling of "referrer".) Including a referrer is not
compulsory, so be prepared for it not to be available.
 
G

Guy Tamir

That would be the "referer" header in the HTTP request. (Note that it is

an accidental misspelling of "referrer".) Including a referrer is not

compulsory, so be prepared for it not to be available.

Thanks for reply,
In what cases will i have this header? is there something i can do to enforce having it?
Are there any other ways?
 
J

Joel Goldstick

Thanks for reply,
In what cases will i have this header? is there something i can do to enforce having it?
Are there any other ways?
--

You can look in the server logs if you have them available. If the
visitor supplied a referer value in the header, it will be in the log.
You don't have any say in this from your end.

If you are the creator of your own website you might like to add
google analytics to your pages. This is done with a little javascript
that google provides.

Although there may be a python angle to your question, it isn't apparent yet.
 
R

random832

Thanks for reply,
In what cases will i have this header?

In practice, you'll usually have it, except in cases where the user has
bookmarked your site, typed/pasted the URL directly, had it opened by an
external program, or taken action to block referers from being sent
(this last one is uncommon)
is there something i can do to
enforce having it?

You can refuse to serve the content if it's not present. But this will
annoy users since they can't bookmark it or open it from an external
program.
 
S

Steven D'Aprano

On Mon, 26 Aug 2013 08:03:33 -0700, Guy Tamir wrote:

[asking about Referer header]
In what cases will i have this header? is there something i can do to
enforce having it? Are there any other ways?

The Referer header is in the HTTP Request that is made to your server.
What server are you using? If it is a custom server written in Python,
then this is a legitimate question for this list. Otherwise, check the
documentation for your server. Any decent web server will already deal
with referrers, and any decent web analytics software will show you the
information collected.

http://en.wikipedia.org/wiki/List_of_web_analytics_software


As for enforcing a referer, that's a really low, dirty thing to do, and I
will not give you any hints as to how to do such a thing. Websites that
take different actions depending on where you are coming from are the
lowest of the low. Need a hand disposing of a body? Yeah, there are
legitimate reasons for this, I'll help if I can. Forcing visitors to your
website to set the Referer header? Nope, no way.
 
C

Chris Angelico

Need a hand disposing of a body? Yeah, there are
legitimate reasons for this, I'll help if I can. Forcing visitors to your
website to set the Referer header? Nope, no way.

Friends help friends move bodies. But even they don't help move headers.

ChrisA
 

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

Staff online

Members online

Forum statistics

Threads
474,219
Messages
2,571,125
Members
47,731
Latest member
PasqualePf

Latest Threads

Top