可变的php空建议

// gets the user IP Address
$user_ip=$_SERVER['REMOTE_ADDR'];

if (empty($user_ip)) {
    // ...
} else {
    $id3 = $row['id'];
    $titlesong = $row['title'];
    $check_ip = mysqli_query($conn, "select userip from pageview where page='$titlesong' and userip='$user_ip'");

    if (mysqli_num_rows($check_ip)>=1) {
        // ...
    } else {
        $insertview = mysqli_query($conn,"insert into pageview values('$id3','$titlesong','$user_ip','$year','$month','$day')");
    }

    // some data...
}

I have made this code to get the pageviews inserted in database, but i get some blank ips, I have used if (empty($user_ip)) to not insert that viewer in database, but it did not work, can you point me to the right direction?

You can also include $user_ip == '':

if( (empty($user_ip)) || ($user_ip == '') )

You should definitively look for a better IP format checker, but a minimal one for IPv4 could be:

if( strlen($user_ip) < 7 )

because of counting at least 4 numbers one digit each, and 3 dots.

Use PHP's FILTER_VALIDATE_IP

Read up on W3Schools FILTER_VALIDATE_IP

Additional parameters can be found on PHP Docs FILTER_VALIDATE_IP