Please tell me why the IP address of each of my registered users is displayed as 0.0.0.0
Fllllll
Fllllll 2017-11-07 16:21:29
0
3
1562

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 correct1.png

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);


?>


Fllllll
Fllllll

reply all (2)
Peter_Zhu

If you are a Mac computer, then the local host IP is 0.0.0.0

    寻觅 beyond

    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

    • reply The output of $_SERVER['REMOTE_ADDR'] is::1 I don’t understand what you said later.
      Fllllll author 2017-11-09 14:35:27
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!