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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
$log=$_SERVER['HTTP_REFERER']; $l1=strtok($log,"/"); $l2=strtok("/"); $l3=strtok("&"); if (substr_count($l3,"search")!=0) { // OK moteur de recherche if (!file_exists("mot_referer.txt")) { $fp=fopen("mot_referer.txt","w");fclose($fp); } //decoupe les mots clefs dans un tableau preg_match("/q=[^&]+&/",$log,$chaine); $mots=$chaine[0]; $mots=str_replace("q=","",$mots); $mots=str_replace("&","",$mots); $mot=explode("+", $mots);
$i=0; // on va chercher dans le fichier si le mot existe deja while($mot[$i]!=false) { $mot[$i]=utf8_decode(urldecode($mot[$i])); $motfich=file("mot_referer.txt"); $ii=0; $trouv=0; while($motfich[$ii]!=false) { $nbr=strtok($motfich[$ii],":"); $clef=trim(strtok(":")); if ($clef==strtolower($mot[$i])) { $motfich[$ii]=($nbr+1).":".$clef."\n"; $trouv=1;break; } $ii++; } if ($trouv==0) { // si il existe pas on l'ajoute $fp=fopen("mot_referer.txt","a"); fputs($fp,"1:".strtolower($mot[$i])."\n"); fclose($fp); } else { // si il existe apres l avoir incremente, on reecrit tout $ii=0;$fp=fopen("mot_referer.txt","w"); natcasesort($motfich); $motfich=array_reverse($motfich); while($motfich[$ii]!=false) { if (trim($motfich[$ii])!="\n") fputs($fp,$motfich[$ii]); $ii++; } fclose($fp); } $i++; } } |