Last active
February 14, 2022 16:29
-
-
Save titomus/62ea5ae9a5cc50e8415f297491e5c13b to your computer and use it in GitHub Desktop.
Récupérer moteur, mot clé et page de la provenance du visiteur
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function analyse($ref){ | |
$refe = parse_url($ref); | |
parse_str($refe['query'], $query); | |
$host = $refe['host']; | |
switch ($host){ | |
case (strpos($host, '.google.') !== false): | |
$moteur = "Google"; | |
$mot_cle = $query['q']; | |
$page = $query['start']; | |
if (!$page){ | |
$page = 1; | |
} else { | |
$page = ($page / 10) + 1; | |
} | |
break; | |
//Yahoo | |
case (strpos($host, '.yahoo.') !== false): | |
$moteur = "Yahoo"; | |
$mot_cle = $query['p']; | |
$page = $query['b']; | |
if (!$page){ | |
$page = 1; | |
} else { | |
$page = (($page - 1) / 10) + 1; | |
} | |
break; | |
//Bing | |
case (strpos($host, '.bing.') !== false): | |
$moteur = "Bing"; | |
$mot_cle = $query['q']; | |
$page = $query['first']; | |
if (!$page){ | |
$page = 1; | |
} else { | |
$page = (($page - 1) / 10) + 1; | |
} | |
break; | |
} | |
return array( | |
'moteur' => stripslashes($moteur) , | |
'mot' => stripslashes($mot_cle) , | |
'page' => stripslashes($page) | |
); | |
} | |
echo '<pre>'; | |
var_dump(analyse($_SERVER['HTTP_REFERER'])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment