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
Gaining the IP address and storing it????
Moderator: General Moderators
Should be stored in $_SERVER['REMOTE_ADDR']
see http://www.php.net/manual/en/reserved.variables.php
see http://www.php.net/manual/en/reserved.variables.php
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());
?>