1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| $ip = $_SERVER['REMOTE_ADDR'];
$ip_long = sprintf("%u", ip2long($ip));
$date = date('Y-m-d');
// va chercher le country dans la table ip2country
$bdd=$con->prepare('SELECT * FROM ip2country WHERE range_start <= :ip_long AND range_end >= :ip_long LIMIT 1');
$bdd->bindValue(':ip_long', $ip_long, PDO::PARAM_INT);
$bdd->bindValue(':ip', $ip, PDO::PARAM_INT);
$bdd->execute();
$result = $bdd->fetchAll();
foreach ($result as $r) {
$range_start=$r['range_start'];
$range_end=$r['range_end'];
$country_code=$r['country_code'];
$country_name=$r['country_name'];
// va inscrire les stats et le country de la table ip2country
$query = $con->prepare("INSERT INTO stats_visites (ip, date_visite, pages_vues, range_start, range_end, country_code, country_name)
VALUES (:ip , :date , 1, :range_start, :range_end, :country_code, :country_name)");
$query->execute(array(
':ip' => $ip,
':date' => $date,
':range_start' => $range_start,
':range_end' => $range_end,
':country_code' => $country_code,
':country_name' => $country_name
));
} |
Partager