Recevoir par mail les infos géographiques récupérees sur un client

Résolu/Fermé
ananias8686 Messages postés 86 Date d'inscription samedi 9 février 2019 Statut Membre Dernière intervention 19 août 2023 - Modifié le 17 avril 2020 à 02:04
ananias8686 Messages postés 86 Date d'inscription samedi 9 février 2019 Statut Membre Dernière intervention 19 août 2023 - 17 avril 2020 à 15:44
Bonjour, je voudrais savoir comment recevoir par mail les infos géographiques récupérées sur un client a partir du formulaire qu'il a rempli.
Mon code fonctionne très bien, je reçois le formulaire par mail mais comment ajouter à ce formulaire le pays et détecter si l'Utilisateur utilise un proxy. J'ai écrits un scripts php qui récupére tout sur le visiteur(pays+utilisation proxy ou pas) mais je ne sais pas comment l'integrer à mon code pour le recevoir également par mail.
J'ai besoin d'aide svp:
Mon code php pour afficher info géo:
<?php
$ip = $_SERVER["REMOTE_ADDR"];
$api_url = 'http://ip-api.com/json/'.$ip.'?fields=country,city,proxy';
$api_content = file_get_contents($api_url);
$api_content_array = json_decode($api_content,true);
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
        <title>Infos IP</title>
        </head>
        <body>
     <?php
echo '<strong><p style="text-align: center;">INFOS</p></strong>';
echo "<br />";
echo "<strong>PAYS: </strong>";
echo $api_content_array['country'];
echo "<br />";
echo "<strong>VPN: </strong>";
echo $api_content_array['proxy'] ? 'ATTENTION VPN actif' : 'Pas de VPN actif';
        ?>
        </body>
</html>

Formulaire html:
<form id="form1" method="post">
                
    <label for="nom">Nom</label>
    <input type="text" name="le_nom" id="nom" />
    <label for="email">E-mail</label> 
    <input type="email" name="mail" id="email" />
     <button name="submit" type="submit" id="submit">Envoyer</button>
                
</form>

Script d'envoie de mail:
<?php 
    $to = "mail@e-mail.com";
        $le_nom = $_POST['nom'];
        $email = $_POST['email'];
    $subject = "Objet";
    
    $message = " 
    NOM: $le_nom\n
    EMAIL: $email";

    $headers = "From:" . $email;
    mail($to,$subject,$message,$headers);
?>
A voir également:

2 réponses

jordane45 Messages postés 38138 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 avril 2024 4 649
17 avril 2020 à 08:34
Bonjour,

https://www.google.com/search?q=php+check+if+user+using+proxy

https://www.google.com/search?q=php+get+user+country
ce qui peut te conduire à trouver un code comme celui la:

/**
* Fonction trouvée ici :
* https://stackoverflow.com/questions/12553160/getting-visitors-country-from-their-ip
*/
function ip_info($ip = NULL, $purpose = "location", $deep_detect = TRUE) {
    $output = NULL;
    if (filter_var($ip, FILTER_VALIDATE_IP) === FALSE) {
        $ip = $_SERVER["REMOTE_ADDR"];
        if ($deep_detect) {
            if (filter_var(@$_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP))
                $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
            if (filter_var(@$_SERVER['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP))
                $ip = $_SERVER['HTTP_CLIENT_IP'];
        }
    }
    $purpose    = str_replace(array("name", "\n", "\t", " ", "-", "_"), NULL, strtolower(trim($purpose)));
    $support    = array("country", "countrycode", "state", "region", "city", "location", "address");
    $continents = array(
        "AF" => "Africa",
        "AN" => "Antarctica",
        "AS" => "Asia",
        "EU" => "Europe",
        "OC" => "Australia (Oceania)",
        "NA" => "North America",
        "SA" => "South America"
    );
    if (filter_var($ip, FILTER_VALIDATE_IP) && in_array($purpose, $support)) {
        $ipdat = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=" . $ip));
        if (@strlen(trim($ipdat->geoplugin_countryCode)) == 2) {
            switch ($purpose) {
                case "location":
                    $output = array(
                        "city"           => @$ipdat->geoplugin_city,
                        "state"          => @$ipdat->geoplugin_regionName,
                        "country"        => @$ipdat->geoplugin_countryName,
                        "country_code"   => @$ipdat->geoplugin_countryCode,
                        "continent"      => @$continents[strtoupper($ipdat->geoplugin_continentCode)],
                        "continent_code" => @$ipdat->geoplugin_continentCode
                    );
                    break;
                case "address":
                    $address = array($ipdat->geoplugin_countryName);
                    if (@strlen($ipdat->geoplugin_regionName) >= 1)
                        $address[] = $ipdat->geoplugin_regionName;
                    if (@strlen($ipdat->geoplugin_city) >= 1)
                        $address[] = $ipdat->geoplugin_city;
                    $output = implode(", ", array_reverse($address));
                    break;
                case "city":
                    $output = @$ipdat->geoplugin_city;
                    break;
                case "state":
                    $output = @$ipdat->geoplugin_regionName;
                    break;
                case "region":
                    $output = @$ipdat->geoplugin_regionName;
                    break;
                case "country":
                    $output = @$ipdat->geoplugin_countryName;
                    break;
                case "countrycode":
                    $output = @$ipdat->geoplugin_countryCode;
                    break;
            }
        }
    }
    return $output;
}

1
ananias8686 Messages postés 86 Date d'inscription samedi 9 février 2019 Statut Membre Dernière intervention 19 août 2023
17 avril 2020 à 09:19
Bonjour,
Je vous remercie pour l'aide
Comment utiliser cette fonction pour recevoir le tout par mail car je souhaite recevoir le formulaire rempli (nom+e-mail + les infos IP). Mon code d'envoie de mail fonctionne bien mais comment recevoir aussi info IP dans le mail.
Merci
0
jordane45 Messages postés 38138 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 avril 2024 4 649
17 avril 2020 à 09:32
tu appelles cette fonction dans ton code, tu stockes le résultat dans une variable
puis tu insères cette variable dans $message
0
ananias8686 Messages postés 86 Date d'inscription samedi 9 février 2019 Statut Membre Dernière intervention 19 août 2023 > jordane45 Messages postés 38138 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 avril 2024
17 avril 2020 à 15:44
J'ai utiliser cette fonction en faisant une include de mon fichier php, ça marche parfaitement
ob_start();
include "ip.php";
$info_ip = ob_get_flush();
0