This post shows how to use PHP to extract the keywords searched on by a user when they found your website using a seach engine. Bing, Google and Yahoo are covered here and you can easily add your own to the PHP code supplied.
PHP functions used
The code example here uses the parse_url function to extract the parts from the referer URL and then the parse_str function to extract the parts of the query string into array variables.
The referer URL is stored in the $_SERVER PHP superglobal as $_SERVER['HTTP_REFERER'], but only if it was set by the web browser.
Referer URL examples
Here's some example referer URLs from Bing, Google and Yahoo from people reaching this blog.
You can see from looking at the URLs that Bing and Google store the keyword word as the "q" variable and Yahoo does it with "p".