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

D

dermoon

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

I use win2k on this server.

On linux I used os.environ[''], but it seemes it's not available on
win2k, is this correct?

However, how do I get the address-string?

Any help would be greatfully appreciated!

-Chris
 
J

John J. Lee

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

I use win2k on this server.

On linux I used os.environ[''], but it seemes it's not available on
win2k, is this correct?
[...]

Depends which server you're using, I guess (certainly, os.environ is
available in the usual standalone Python execution environment on
Windows, but programs running in webservers will no doubt have all
kinds of variations). Is this IIS or something?

If you want to have the same environment as on Linux, remember Apache
runs on Windows too (if that's what you were using).
However, how do I get the address-string?
[...]

Read your server's documentation.


John
 
J

John J. Lee

I want to fetch the address from the web-browser when it
visits a page on my web-server.
[...]

BTW, this isn't a Python issue, so this is really the wrong newsgroup.


John
 
A

Alan Kennedy

dermoon said:
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?
 

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

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top