Forum Moderators: coopster
People find my site through Google (y'know, the search engine). When they click through to my site, the search words and phrases are passed to the server - they turn up in my stats package at least . . .
What I want to know is - can I make that information available to a PHP script running on my page? For example, user searches for 'widgets'. My site comes up at no.1, naturally. User clicks on the link to my page, and a PHP script echos 'So, you're looking for info about widgets' onto the top of the page.
Obviously, there would be a default option for non-search engine traffic.
I hope that's clear. Is it possible? I've posted this in the PHP forum as I'm less incompetent with PHP than I am with other scripting languages - if something else would be more suitable, I'd still be interested.
Thanks
Roddy
However, for those user agents that do have it turned on, you can customize the welcome message. Everyone else would get your default option.
if(!isset($HTTP_REFERER)){
print "General message goes here.";
}
else{
$query = split("[?]",$HTTP_REFERER);
$div = split("[&]",$query[1]);
foreach($div as $var){
if(preg_match("/q=/",$var)){
$var = ereg_replace("q=","",$var);
$var = ereg_replace("+"," ",$var);
print "So, you're looking for info about $var";
}
else{
}
}
}
if(!isset($HTTP_REFERER)){
print "General message goes here.";
}
to something like:
if(!isset($HTTP_REFERER))
{
print "<script TYPE=\"text/javascript\">\n";
print "if(document.referrer)\n{\n";
print " var args = new Object();\n";
print " var query = document.referrer.substring(1);\n";
print " var pairs = query.split(\",\");\n";
print " document.write(\"So, you\'re looking for info about \");\n";
print " for(var i = 0; i < pairs.length; i++)\n {\n";
print " var pos = pairs[i].indexOf(\"=\");\n";
print " if(pos == -1){continue;}\n";
print " var value = pairs[i].substring(pos+1);\n";
print " document.write(unescape(value));\n }\n}\n</script>\n";
}
GGG
Hey, looking for info on knick knack paddywhack give your dog a bone
..which doesn't look good.
Instead, simply do a strstr() on $_SERVER["HTTP_REFERER"] for your primary keywords, and then display relevant welcome text for those keywords.
That way you're in complete control of the text, and are still creating a relevant page, for example:
$referer = strtolower($_SERVER["HTTP_REFERER"]);if (strstr($referer,"dog"))
{
echo("<h1>Dogs simply love our dog food!</h1>");
}
else if (strstr($referer,"bee"))
{
echo("<h1>Bees make a beeline for our bee food!</h1>");
}
else if (strstr($referer,"cat"))
{
echo("<h1>Cats can't get enough of our cat food!</h1>");
}
else if (strstr($referer,"hamster"))
{
echo("<h1>Our hamster food makes your hammy happy!</h1>");
}
else
{
echo("<h1>If your pet could order pet food online, this is where they'd come!</h1>");
}