I think your best bet would be to tear the referrer string down using PHP and then use a LIKE statement to search for something similar in the database.
I would not use the whole referrer string because like you said, it doesn't work
Let me clarify a little. What you can do is use a regular expression to take out anything before or after the .google. so that you are just left with that... Then you would use the resulting string to search with.
Bookmarks