Page 1 of 1

Gaining the IP address and storing it????

Posted: Wed May 23, 2007 5:10 am
by otd
Can anyone help???

basically i have created a basic forum, that does not require user log in, therefore im after a bit of code that gets the ip address of the user that inputs a message and store it within my mysql database, really dont know how to do this and any help would be greatly appreciated.

Many Thanks

Chris

Posted: Wed May 23, 2007 5:41 am
by otd
Any help on this would be greatly appreciated

Many Thanks in advance

Posted: Wed May 23, 2007 6:06 am
by volka
Should be stored in $_SERVER['REMOTE_ADDR']
see http://www.php.net/manual/en/reserved.variables.php

Posted: Wed May 23, 2007 6:09 am
by smudge

Code: Select all

<?php
$ip=$_SERVER['REMOTE_ADDR'];
$conn=mysql_connect("hostname","username","password");
$sql="INSERT INTO table (ipaddress) VALUES ($ip)";
$result=mysql_query($sql,$conn) or die(mysql_error());
?>
Something along those lines. It may take a little tweaking, but I hope it helps.

Posted: Wed May 23, 2007 8:10 am
by otd
Smudge, just would like to say a big thank you, played around abit with that code and it worked perfectly!!

So thank you very much!!

Your a star!

Chris