You can't see the last page the user was on if you type a new URL in. HTTP_REFERER
is only set when you click on a link. It'd be a pretty big privacy invasion if you could see whatever arbitrary URL the user was previously viewing.
Detecting url user visited before coming to my site in Rails
-
16-03-2022 - |
문제
I would like to save the url that user visited right before landing to my site. How should I do it in Rails?
I tried
request.env["HTTP_REFERER"]
but couldn't retrieve the previous url.
May be this is a wrong way to test it, but here is what I did:
- I go to a page, say, google.com
- Then I type in: localhost:3000. Then has debugger on to catch request.env["HTTP_REFERER"]. But it yields nil
Is HTTP_REFERER only available when user comes to my site via a redirect, and not manually type it the address?
Thank you.
해결책
다른 팁
This is sent in the HTTP headers as "referer". So, request.referer should have what you need if the user's browser and/or any proxies are not filtering it out.
제휴하지 않습니다 StackOverflow