Gaining the IP address and storing it????

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
otd
Forum Newbie
Posts: 18
Joined: Mon May 21, 2007 8:50 am

Gaining the IP address and storing it????

Post 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
otd
Forum Newbie
Posts: 18
Joined: Mon May 21, 2007 8:50 am

Post by otd »

Any help on this would be greatly appreciated

Many Thanks in advance
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Should be stored in $_SERVER['REMOTE_ADDR']
see http://www.php.net/manual/en/reserved.variables.php
smudge
Forum Contributor
Posts: 151
Joined: Sun May 20, 2007 12:13 pm

Post 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.
otd
Forum Newbie
Posts: 18
Joined: Mon May 21, 2007 8:50 am

Post 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
Post Reply