Skip to content

Instantly share code, notes, and snippets.

@titomus
Last active Feb 14, 2022
Embed
What would you like to do?
Récupérer moteur, mot clé et page de la provenance du visiteur
<?php
function analyse($ref){
$refe = parse_url($ref);
parse_str($refe['query'], $query);
$host = $refe['host'];
switch ($host){
//GOOGLE
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