[PHP] Controllare cosa cercano le persone per raggiungere il tuo sito!
Posted on 21. Nov, 2009 by daniele in php, tutorials
Grazie a questo utilissimo script sarà possibile scoprire cosa la gente ha cercato su motori di ricerca per accedere al tuo sito.
< ?php $search_engines = array("google" => "q", "yahoo" => "p"); $url = parse_url($_SERVER["HTTP_REFERER"]); // Parse the referring url and assign it to $url $host = trim(str_ireplace("www.", "", $url['host'])); // Get the hostname from the referring site and remove www. from it and any whitespace then assign it to $host. parse_str($url['query'], $query); // Now parse the queries such as <strong>?hl=en&source=hp&q=PK-Tuts</strong> and allow us to grab the individual query then put them all in an array in $query. foreach($search_engines as $engine => $query){ // Go through the array $engine_chk = stripos($host, $engine); // Check if the referring hostname has $engine in it anywhere. if ($engine_chk !== false) { // If it does then echo "You have been referred by " . $engine . " to this site by searching for '" . $url . "'"; // Echo the message including the name of the search engine and what they searched for /** * DO YOUR DATABASE STUFF HERE */ } } ?>





Leave a reply