I’m attempting to grab the search query from search engine referrals. Most pass the search query with the ?q parameter, however yahoo is using ?p so I’m trying to use a switch statement but to no avail. Here is what I have:
<?php
$parse = parse_url($_SERVER["HTTP_REFERER"]);
$se = $parse["host"];
$raw_var = explode("&", $parse["query"] );
foreach ($raw_var as $one_var) {
$raw = explode("=", $one_var);
$var[$raw[0]] = urldecode ($raw[1]);
}
$se = explode (".", $se);
switch ($se[1]) {
case "yahoo":
$sekeyword = $var["p"];
break;
default:
$sekeyword = $var["q"];
}
print_r ($se);
echo "<br>";
echo "search query is: $sekeyword";
?>
Here is what I am seeing:
$se = Array ( [0] => au [1] => search [2] => yahoo [3] => com )
$sekeyword is null, however if I specify the default $var as “p” within the switch then the search query from yahoo is passed correctly.
You’re
switching on$se[1]but in your case the string “yahoo” is in$se[2]..