Forums

Can I use access-log data on my web-pages in real-time?

Dear All,

I'm a newbie I hope to make a web page which shows some data from access-log.

e.g Someone who vists my web page via google search result like this;

a) a user vists with "https://www.google.com/search?q=seattle+cafe" (not sure but I think it is in access-log file) Result on my web page, "Seattle's best cafe is my brand name"

b) a user vists with "https://www.google.com/search?q=san+francisco+cafe" Result on my web page, "San Francisco's best cafe is my brand name"

It is a just example, I just hope to get some words from log data. It must show it on my web page in real-time when a user vistis. Is it possible to do?

Thank you all.

You could get that from the access log, but it would be better to get it directly from the headers (which is where the access log gets it from). The header in question is called Referer (which is incorrectly spelled, but the mis-spelling has somehow become a standard).

You can find out how to get that header if you google for the name of your web framework plus "get referer". For example, googling for "django get referer" returned this documentation page in the results.

It's worth noting that not every request will have a referer. Many people regard the leakage of information like where they came from before visiting your site as a privacy problem, so they switch it off in their browser. So don't rely on it always being set.