search

Home  >  Q&A  >  body text

Please tell me why the IP address of each of my registered users is displayed as 0.0.0.0

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

<?php

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<br/>";

}else{

echo "Failed";

}

mysqli_close($conn);


?>


FllllllFllllll2696 days ago1673

reply all(3)I'll reply

  • 天蓬老师

    天蓬老师2017-11-11 22:40:30

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

    reply
    0
  • 寻觅 beyond

    寻觅 beyond2017-11-09 13:24:33

    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
    0
  • Fllllll

    The output of $_SERVER['REMOTE_ADDR'] is::1 I don’t understand what you said later.

    Fllllll · 2017-11-09 14:35:27
  • Cancelreply