My Google adwords destination URL is: http://www.mydomain.com?kw={keyword} this will ensure that Google Adwords passes my keyword to my landing page as a variable "kw". Now where ever on my page I place <?php echo $kw;?> I can show these keywords on my page. All is cool so far. All I want is to maintain this variable across all the pages of my site. I could do it by passing it in the url but this is very messy. There is a way by adding some code to start of every page of my site. I have tried all sorts and can't get it to work. Could some explain in baby steps what I have to do please? I appreciate any help Thanks Mike
Use a cookie: if (isset($_GET['kw'])) { setcookie('keyword', $_GET['kw']); $kw = $_GET['kw']; } if (isset($_COOKIE['keyword'])) { $kw = $_COOKIE['keyword']; } PHP:
Thank you for that, but it did not work. I have the echo on every page but it only echoed on the page that I loaded. with ?kw=Testing at the end of the url it echos: "Testing" on page. It did not pass through to other pages. Thanks again, though. A cookie was set but it is not reading it?? Regards Mike
Ok I got it. In one place on one of my pages I need to display the keyword without any spaces. This code was doing this: <?php echo str_replace( ' ', '_', $_GET['kw'] );?> Code (markup): It was stripping the spaces and replacing them with "_" but for some reason it will not work with that cookie code in place. I have taken my: <?php echo str_replace( ' ', '_', $_GET['kw'] );?> Code (markup): out and it all works as it should now on every page. But in this particular place in one page I cannot have spaces in the keyword phrase. Any ideas? Thank you Regards Mike
Use Session, that may be better Are you using cookies, if you then why are you using the GET in the pages?
Thanks for your help. I have it working now. I did not need to strip the spaces after all. JDevereux's post fixed my problem, so big thank you. Regards Mike
I need a little more help on this please... I checked my cookie after I tested it and it expires at the end of the session. How would I set to expire after say 30 days? Thanks Mike