Library code snippets
Get the visitor's IP address
Whenever a browser sends a request for a page, it also sends a number of other headers to the script, containing information such as the browser type. It also includes information such as the visitors IP address. This can be particularly useful when creating an online security scan, or logging their IP address in an online forum.
There are two server variables of interest; REMOTE_ADDR and HTTP_X_FORWARDED_FOR.
As many visitors access the internet via a third party (ie their ISP), REMOTE_ADDR
does not always contain their IP address... it contains their ISP's address.
If this is the case, most browsers then store the users IP address in the HTTP_X_FORWARDED_FOR
variable. So, first, we check HTTP_X_FORWARDED_FOR, and then if
that is empty, we try REMOTE_ADDR instead:
Dim sIPAddress
sIPAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If sIPAddress="" Then sIPAddress = Request.ServerVariables("REMOTE_ADDR")
One other thing worth bearing in mind. If the user also accesses the internet
via a Proxy server, then HTTP_X_FORWARDED_FOR will contain the
Proxy's IP address. If this is the case, there is no way to get the users 'real'
IP address.
Related articles
Related discussion
-
Header and Footer in Web page print
by fhajaj (4 replies)
-
help me to get simple requirement
by Slicksim (1 replies)
-
Gridview -> Template Field -> Button
by antti.simonen (1 replies)
-
Classic ASP : Page expires
by chezhian_in05 (0 replies)
-
ASP VS PHP
by paulfp (9 replies)
Related podcasts
-
ASP.NET Caching and Performance
Steve Smith, owner of ASP Alliance and Lake Quincy Media joins us today to teach us about some hidden gems in ASP.NET caching and performance. Steve’s expertise in this area comes from first-hand experience as Lake Quincy’s ad system serves over 60 requests per second and handles over 150 million...
Related jobs
-
Microsoft .Net Architect
in AMSTERDAM (€50K-€90K per annum) -
Microsoft Dynamics CRM Technical Consultant
in Netherlands (€50K-€90K per annum) -
Technical Support Engineer EMEA
in Reading (£50K-£50K per annum) -
Solutions Engineer
in Reading (£50K-£60K per annum)
what if when ever a user enters my site his/her ip address will be saved in a database? for me this is a good protection idea for no good users u save their ip in a database then if they do no good they will be denied the next time they enter the site... is there any code for this. thnx in advance
How do you log a visitors IP address if register globals is off? Most hosts only have register globals off for security reasons.
how can i see the online users` ips? have you got an idea ?
This thread is for discussions of Get the visitor's IP address.