I’m attempting to get the referrer URI in Kohana 3.2 using the following code:
$referrer = $this->request->referrer();
var_dump($referrer);
However the function returns NULL, I’m expecting it to return the page I left to get to this one.
Is that how it should work… and if so what am I missing or doing wrong?
This is being run in the Controller.
Documentation here: http://kohanaframework.org/3.2/guide/api/Request#referrer
The issue I was having was cause by the way my Kohana system is setup. Basically I have a routeHandler in the middle of my system which controls the routes users take. In that script a new request was generated and then executed.
What was happening was when creating the new request object it wasn’t having the referrer uri added to it. I have added the following code and now I am able to get the referring uri from the controller at the end of the routing process.
Alternatively a cleaner more native solution as suggested by atma is the following: