Register unique ID from IP address
Posted: 04 Apr 2018, 06:52
I have a problem it does not register all IP-addresses from the visitors with a Unique Key made from their IP-address.
I see also that some visitors have a different Unique Key made from their IP-address, this I saw in another table what register all IP-addresses without a Unique Key.
To get a Unique Key I use str_replace from the IP-address
but some str_replace gives a different number then their IP-address (this i don`t mind)
- This is the SQL INSERT INTO code
Is their another posibility were i can give visitors a Unique Key (id) from their IP-address, that will register all visits ???
I see also that some visitors have a different Unique Key made from their IP-address, this I saw in another table what register all IP-addresses without a Unique Key.
To get a Unique Key I use str_replace from the IP-address
but some str_replace gives a different number then their IP-address (this i don`t mind)
Code: Select all
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$today = date("Y-m-d-H.i.s");
$intip = str_replace(".","",$ip);
$details = json_decode(file_get_contents("ipinfo.io/{$ip}"));
echo $details->country; // -> "US"
?>
Code: Select all
<?php
$con=mysqli_connect("127.0.0.1","visitors","123456","visitors");
// Check connection
if (mysqli_connect_errno()) echo "Failed to connect to MySQL: " . mysqli_connect_error();
// Perform queries
mysqli_query($con," INSERT INTO ip_register (id,ip_adress,country,date)
VALUES ('$intip','$ip','$details->country','$today') ON DUPLICATE KEY UPDATE ip_adress ='$ip' ");
mysqli_close($con);
?>