This is a website by Willem van Zyl

I'm a project manager, software developer, Apple evangelist and geek from South Africa. I'm passionate about web and mobile application development, usability, productivity, physics, astronomy, science fiction and fantasy.

If you would like to contact me, message me on Twitter or send me an email.

How to gain access to a visitor's IP address in PHP

20 Jun 2009

PHP's HTTP_X_FORWARDED_FOR and REMOTE_ADDR server variables store the IP Addresses of a visitor's connection and any proxy server that their connection was forwarded through.

To use these details in your code, write a script similar to this:

<?php

  $addressForwarded = $_SERVER['HTTP_X_FORWARDED_FOR'];
  $addressRemote = $_SERVER['REMOTE_ADDR'];

  echo "Connection forwarded for: {$addressForwarded} " .
       "and originated from {$addressRemote}.";

?>
Do you like this? Share it:

Copyright © Geekology 2011. All Rights Reserved.

Hosted by Code. Like. Clockwork.