• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 173
  • Last Modified:

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 ?
1 Solution
CGI can run a c program.
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:


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


Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now