Getting user IP

I want to receive the user's ip address when he's browser loads the page.
1. Is it possible to do so in cgi or should it run a c program ? or there is a simpler way ?
2. if to use cgi, how to call it from the html when the page is loaded to the browser ?
gilad111397Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
REMOTE_ADDR
CGI can run a c program.
0
shiversCommented:
further to Ozo's comment...

CGI is not a language as such - it's an interface between a web browser at the client, and a program on the server.  This program may be written in (almost) any language.  Perl is used mostly, but C or C++ is often used where speed is important.

as ozo briefly mentions, there is an environment variable called REMOTE_ADDR that holds the remote user's IP address. this environment variable is set by the web server when your CGI program is called.  in Perl, use:

 $ENV{'REMOTE_ADDR'}

to retrieve it, and in C it can be retrieved using the getenv() function.

There is also a lot of other information about the user that can be retrieved through the use of environment variables - such as:

HTTP_USER_AGENT - user's browser
HTTP_REFERER - the document that the user came from before they got to the CGI

There are others too - i can't think of a URL offhand - but a web search should be productive

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.