Get G search query for dynamic tracking id using PHP

Shirley7788

Newbie
Joined
Apr 21, 2009
Messages
27
Reaction score
2
I want to make my .php link (direct to my aff link) on my LP has dynamic tracking id base on google search query, how can I do that?

example:
search: lose weight
the tracking id become loseweight (better if you can spin it like losew, lw,lweight,lewt)


What I'm currently doing is as below (I'm having problem:()

Top of wordpress post:
<?php $seedvar=$_GET['q'];?>

on LP:
<a href="http://mydomain.com/afflinkredirect.php?id=<?php echo $seedvar;?>">

redirect .php:
<?php
header('Location:http://aff.vendor.hop.clickbank.net/?tid=.$_GET['id']');
exit();
?>

I'm totally noob in coding, just following some example and some trial (no luck and go nuts:confused:). Can somebody kindly help me on this?




P/S: I got this error

1)
Parse error: syntax error, unexpected T_STRING in /home/username/public_html/mydomain.com/recommends/mybestrecommendonEARTH.php on line 2


2)
somehow the link on LP show
http://mydomain.com/afflinkredirect.php?id=
which is blank after id, I thought it would "scrape" the ?q=lose+weight from google search string?
 
No, it will not get the ?q=lose+weight from Google. You can get that parameters only on your script. You will need to find another solution for that.
 
This is the code I'm using now after I done more researching, is any problem inside there?

THE PROBLEM:
When using aff.vendor.hop.clickbank.net/?tid=<?php echo $keywords;?>
the $keywords won't show, just
aff.vendor.hop.clickbank.net/?tid=

I also tried $keywords[0] after I realized $explode the keyword (more than one word) make it an array.
PHP:
<?php
function getReferalHost()  
{  
    $refer = parse_url($_SERVER['HTTP_REFERER']);  
    $host = $refer['host'];  
      
    if(strstr($host,'google'))  
    {  
        return 'Google';  
    }
}

function getKeywords()  
{  
    $refer = parse_url($_SERVER['HTTP_REFERER']);  
    $host = $refer['host'];  
    $refer = $refer['query'];  
      
    if(strstr($host,'google'))  
    {  
        //do google stuff  
        $match = preg_match('/&q=([a-zA-Z0-9+-]+)/',$refer, $output);  
        $querystring = $output;  
        $querystring = str_replace('&q=','',$querystring);  
        $keywords = explode('+',$querystring);  
        return $keywords;}}
?>

P/S: Testing is done through, search on google, click and check is the tid working.
 
PHP:
<?php

function GetKeywords()
{
$url=$_SERVER['HTTP_REFERER'];
$arr = parse_url($url); 

$host = $arr['host']; 
if(strstr($host,'google'))  
    {
    $parameters = $arr["query"];
    parse_str($parameters, $data);
    $query=$data['q'];

    return explode("+", $query);  
    }
}
?>
 
That's a neat code!

but I wonder what should I put after /?tid= ?



edit: Is it
/?tid=<?php echo $query; ?>
OR
/?tid=<?php echo $query[0]; ?>

the part after tid= still blank :(
 
Last edited:
It depends...

If the user searched: how to lose weight, and u want to use same query as a tid. Than this line in my code:
PHP:
return explode("+", $query);
should look like that:
PHP:
return $query;
And usage:
PHP:
<?php echo GetKeywords(); ?>


But if u want do something with searched query before putting it to the link
this line is ok:
PHP:
return explode("+", $query);
It's returning each single word from searched query in single cell in array (function is returning array).

Example usage:
PHP:
<?php
$keywords=GetKeywords(); 
/*now $keywords is array with word's from searched query*/

for ($i = 0; $i < count($keywords); $i++)
   {
    echo $keywords[$i]."< /br>";
   }
/*this will display every word from searched query in new line*/
?>
 
:1::1::1:


Thanks for your quick response, now I know how they work and perhaps I can tweak them a little, 7hours of php tutorial was finished!:sombrero:

I'm like hit the jackpot now because before that I can't see anything but blank after id everytime I click into my website.

Sorry I cannot hit thanks button twice.
 
Back
Top