Reputation: 83
I am locally designing a website and I am testing a function within PHP that captures and stored the ip address of the client however I am simply getting a value of 0. The code is:
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
The ip is then added to the mysql and stored as an integer using the code:
$query = "INSERT INTO users (id, email, salt, passhash, regdate, last_login_date, regip, last_login_ip) VALUES ( NULL, ?, ?, ?, NOW(), NOW(), ?, ?)";
$stmt = mysqli_prepare($dbc, $query);
//i Interger
//d Doubles
//s Everything Else
mysqli_stmt_bind_param($stmt, "sssii", $email, $salt, $passhash, $ip, $ip);
Would the reason that the value is only 0 because I am running the website locally, or am I missing a step?
Thanks :)
Upvotes: 0
Views: 289
Reputation: 1375
You shouldn't store your ip address in an unsigned integer field. Store it in an varchar format and it should fix your problem. Integer is expecting a normal number, not something with multiple .
in it.
Upvotes: 1