Why is the IP address of each of my registered users displayed as 0.0.0.0? I can be sure that the code is correct
if(trim( $_POST['password'])!=trim($_POST['firmPassword'])){
exit("The passwords entered twice are inconsistent");
}
$userName=trim($_POST['userName']);
$password=md5(trim($_POST['password']));
$time=time ();
$ip=ip2long($_SERVER['REMOTE_ADDR']);
echo $ip;
$conn=mysqli_connect("localhost","root ","");
if(mysqli_errno($conn)){
echo mysqli_error($conn);
exit;
}
mysqli_set_charset($conn, 'utf8');
mysqli_select_db($conn,'zhuce_php');
$sql = "insert into user(`userName`,` password`,`createtime`,`createip`) values ('"
. $userName . "','" . $password . "','" . $ time . "','" . $ip . "')";
$result=mysqli_query($conn,$sql);
echo 'The ID inserted by the current user is:' .$conn->insert_id;
if($result){
echo "Success
";
}else{
echo "Failed";
}
mysqli_close($conn);
?>
If you are a Mac computer, then the local host IP is 0.0.0.0
Please confirm first if $_SERVER['REMOTE_ADDR'] is run on your machine, what will be output, is it 127.0.0.1, or:: 1,
Then, ip2long uses ip to convert it into a long integer Type (10 bits), 32-bit ip (ipV4) is converted into an integer, but it is a negative number after conversion, so you need to use sprintf ("%u", $ip) to convert to unsigned int type, then, there is no more, it should That’s the problem