This topic is locked

Change Searchbox Keyword Variable

10/29/2009 7:14:27 PM
PHPRunner General questions
L
Lorenbond author

I am using version 4.2 Build 3.9 Classifieds layout.

I have a php script in my header.php file that captures the Google search engine keyword that a user has entered to locate my page using google search engine.
Example:

<?php

......

$mygooglekeyword = urldecode($a);

......

?>
I can capture and echo the keyword to the screen using: echo $mygooglekeyword;
What I need to do is place the value of this variable >"$mygooglekeyword" in the SearchBox on my list page.
How would this be done? <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=13012&image=1&table=forumtopics' class='bbc_emoticon' alt=':)' />
Thanks, Loren Bond

J
Jane 10/30/2009

Hi,
save it in the session variable in your header:

$_SESSION["mygooglekeyword"] = $mygooglekeyword;


Then assign it in theBefore display event on the Events tab:

$smarty->assign("search_searchfor","value=\"".htmlspecialchars(@$_SESSION["mygooglekeyword"])."\"");
L
Lorenbond author 10/30/2009



Hi,
save it in the session variable in your header:

$_SESSION["mygooglekeyword"] = $mygooglekeyword;


Then assign it in theBefore display event on the Events tab:

$smarty->assign("search_searchfor","value=\"".htmlspecialchars(@$_SESSION["mygooglekeyword"])."\"");



Odly enough this method doesn't work out.

Using this method a delay is created. Like this..
Step (1) Search for a number in Google that brings you back to the web page.

No search will be returned in the search box as expected.
Step (2) Search the same number again in google.

On this second attempt it will return the result in the Search box.
However, thanks to your help I was able to get the result I need by using smarty to assign the keyword result directly to the Searcbox.
Like this.. : if($smarty) $smarty->assign("search_searchfor","value=\"".$mygooglekeyword."\"");
I had to use the "if($smarty)" because I use the header.php with HTML pages that do not load smarty.
Just in case anyone is interested in capturing google search keyword here is the actual code that I use in my header.php file
<?php

$thereferer = strtolower($_SERVER['HTTP_REFERER']);

if (strpos($thereferer,"google")) {

$a = substr($thereferer, strpos($thereferer,"q="));

$a = substr($a,2);

if (strpos($a,"&")) {

$a = substr($a, 0,strpos($a,"&"));

}

$mygooglekeyword = urldecode($a);

if ($smarty) $smarty->assign("search_searchfor","value=\"".$mygooglekeyword."\"");

}

?>