Newbie-question: Fetching web-address from the browser!

Alan Kennedy alanmk at hotmail.com
Fri Sep 12 06:25:47 EDT 2003


dermoon wrote:
> I want to fetch the address from the web-browser when it
> visits a page on my web-server.

Hmmm, what exactly do you mean by the "address from the web-browser".
Possibilities include (with solutions for CGI scripts)

1. The IP address of the remote machine, i.e. the numerical address of
computer on which the browser is running?

If yes, try the "REMOTE_ADDR" environment variable, like so

import cgi, os
remote_addr = os.environ['REMOTE_ADDR']

2. The name of the remote machine on which the browser is running,
e.g. 'k109-8.bas1.dbn.dublin.eircom.net'? If yes, do a reverse DNS
lookup on the IP address discovered above, like so

import cgi, os, socket
remote_addr = os.environ['REMOTE_ADDR']
remote_name = socket.gethostbyaddr(remote_addr)[0]

3. The address of the web page that contained a link to your page,
i.e. the "HTTP Referer"? If yes, take a look at the "HTTP_REFERER"
environment variable, like so

import cgi, os
referer_url = os.environ['HTTP_REFERER']

Note that not all browsers supply the "referer" header, and some
firewalls/proxies drop it, for privacy reasons.

Is any of these what you meant? Or did you mean something else?

-- 
alan kennedy
-----------------------------------------------------
check http headers here: http://xhaus.com/headers
email alan:              http://xhaus.com/mailto/alan




More information about the Python-list mailing list