Determining a visitor's IP Address in PHP

11:02.30 - Tuesday 10th February 2004   (Link to This Entry)


Experimenting with IPs and wotnot, I came up with the following PHP 3-liner which finds a users IP address, irrespective of whether they're behind an invisible proxy of the type NTL seem to love. This snippet checks three possible server variables and stores it's discovery in $addr ready for you to use.

<?
 $addr=$_SERVER['HTTP_X_FORWARDED_FOR'];
 if(strlen($addr)<7) { $addr=$_SERVER['HTTP_CLIENT_IP']; }
 if(strlen($addr)<7) { $addr=$_SERVER['REMOTE_ADDR']; }
?>


Granted, it's not he most useful PHP in the world, nor is it the most technically advanced, and I suppose those '<7' comparisons should really be '==0', but I figured nobody would have an IP shorter than 1.2.3.4 anyway, and it works. Feel free to use it for determining the proper IPs of people using your guestbook, for example.

HOLY CRAP that was LOUD!

12:16.55 - Tuesday 10th February 2004   (Link to This Entry)


Somehow I have even less of a kitchen than I did yesterday. Two guys turned up this morning and started tearing out everything that was left, down to removing the last few tiles from the wall around the window.

There was an old gas pipe sticking up from the kitchen floor that was in danger of preventing the washing machine going in, so one of the lads (Kev I think) removed it. Using an angle-grinder. In the enclosed kitchen, it was quite possibly the loudest thing I've ever heard, outside of a David Lee Roth concert.

It's back...

20:27.38 - Tuesday 10th February 2004   (Link to This Entry)





[ 0 comments pending ]