I am trying to get my new user registration script to log the user's ip address in a db table. I've been told to put in the following line but it doesn't log the ip.
$ip = $_SERVER['REMOTE_ADDR'];
So basically my intention is when people register on the site it logs their ip address in the same table as user name, email address etc. The db table is called user_auth and the field is called remote_addr
Thanks in advance for any help and please respond as if you're addressing a php noob since I am.
Code: Select all
<?php require_once('../Connections/user.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
if($_POST['password'] == $_POST['confirm_password'])
{
$insertSQL = sprintf("INSERT INTO user_auth (password, confirm_password, email, refer, newsletter, `user`) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['password'], "text"),
GetSQLValueString($_POST['confirm_password'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['refer'], "text"),
GetSQLValueString(isset($_POST['newsletter']) ? "true" : "", "defined","'Y'","'N'"),
GetSQLValueString($_POST['user'], "text"));
mysql_select_db($database_user, $user);
$Result1 = mysql_query($insertSQL, $user) or die(mysql_error());
} else {
echo 'Your passwords did not match';
}
}
?>