referer url

Discussion in 'Python' started by pavloutefkros@gmail.com, Jan 28, 2008.

  1. Guest

    Hello all!

    I was wondering, if there is a way to retrieve the referer url with
    python (web-based).
    I tried this:

    import os
    print os.getenv('HTTP_REFERER')

    but it's not working, even thought other http variables do function,
    this one is always a None.

    Thanks in advance.
    , Jan 28, 2008
    #1
    1. Advertising

  2. Tim Chase Guest

    > I was wondering, if there is a way to retrieve the referer url with
    > python (web-based).
    > I tried this:
    >
    > import os
    > print os.getenv('HTTP_REFERER')
    >
    > but it's not working, even thought other http variables do function,
    > this one is always a None.


    This could be for any number of reasons, inter alia:

    1) you don't specify the environment in which your python code is
    running. this may not get stashed in the os.getenv(). In
    Django, it's stashed in request.META.HTTP_REFERER; in CGI, it
    should be in your os.getenv(); in WebStack, the trans parameter
    has get_headers()/get_header_values() methods you can use to
    extract the referer; and in other frameworks, they may toss them
    elsewhere.

    2) the browser is configured to protect the privacy of the
    browser, and not send a Referer header

    3) your server may not be configured to include the HTTP_REFERER
    environment variable (improbable, but possible)

    4) your user(s) are coming from a book-marked link where there is
    no Referer to be sent

    -tkc
    Tim Chase, Jan 28, 2008
    #2
    1. Advertising

  3. Guest

    Thanks for the reply.
    1) CGI so i'm doing it right.
    2) this is impossible as i'm doing the exact same thing with another
    language and it utterly works.
    3) the same as above
    4) no..

    this gets nerve breaking!
    , Jan 28, 2008
    #3
  4. Tim Chase Guest

    > 1) CGI so i'm doing it right.

    that's helpful to know

    > 2) this is impossible as i'm doing the exact same thing with another
    > language and it utterly works.


    Just making sure...same browser/setup/configuration, different
    language?

    > 3) the same as above


    kinda figured...most servers give you the HTTP_REFERER, so you'
    have to

    > 4) no..
    >
    > this gets nerve breaking!


    Well, you can always dump the contents of os.environ into your
    output to see if you can find why.

    from cgi import escape
    out.write('<br>'.join([
    '<b>%s:</b>%s' % (escape(k), escape(v))
    for k,v in os.environ.iteritems()
    ])

    -tkc
    Tim Chase, Jan 28, 2008
    #4
  5. Guest

    Thanks for that! i found the variable in "ALL_HTTP" and it's working
    now.
    Thanks again..
    , Jan 28, 2008
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dave wanta

    Re: How to Spoof Referer URL

    dave wanta, Jul 6, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    1,020
    Admin
    Jul 7, 2003
  2. Rune
    Replies:
    4
    Views:
    1,798
  3. Chris Ianson
    Replies:
    1
    Views:
    384
    David Dorward
    Apr 1, 2006
  4. Replies:
    3
    Views:
    6,987
  5. meucat
    Replies:
    0
    Views:
    147
    meucat
    Sep 7, 2006
Loading...

Share This Page