-1

I have this requirement: I need to save the search word made by a user who has come to my site. The site is made in classic asp. I have tried with: Request.ServerVariables ("HTTP_REFERER") Request.ServerVariables ("ALL_HTTP")

But I don't get the search query (q=) https://www.google.com/search?q=house

How can I get the value of q= ?

Max
  • 1

1 Answers1

2

The following code will give you what you are looking for:

    Response.Write(Split(Split(Request.ServerVariables ("HTTP_REFERER"), "?")(1),"=")(1))

For sure, you will need to adapt it : if you don't have query string, it will fail, and the parameter you are looking for needs to be the first one.

TiK
  • 139
  • 1
  • 5
  • It’s not their query, it’s the query that was used by the search engine (in this case google). You are trying to capture the query-string via the referrer, this will not do that. – user692942 Sep 21 '19 at 19:47
  • Yes, you're true. I will post another solution so. – TiK Sep 23 '19 at 10:33
  • Request.QueryString ("q") cannot work. I tried and it doesn't work. I tried all the Server Variables that I found here https://www.w3schools.com/asp/coll_servervariables.asp none works – Max Sep 24 '19 at 07:19
  • I changed my response. – TiK Sep 24 '19 at 14:57
  • Thank you for your Tik engagement but it doesn't work. If I do: Response.Write Request.ServerVariables ("ALL_HTTP") the result is https://www.google.com and not https://www.google.com?q=house so if I use split it goes wrong. Is how Lankymart says the problem is the change made by Google – Max Sep 25 '19 at 13:37