Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How to get full url?

I have this url:

http://mysite/preregistration?userId=18&d=4

I want to get this url precisely from the controller, but cant find a function for it



37.3k
Accepted
answer

Hey

In the controller you just call following

$this->request->getHTTPReferer()


12.0k

$this->request->getHTTPReferer() This can not be relied upon as it requires the user's browser to send this info, which they may have disabled. If you want to find out which page a user was previously on more reliably, you could use cookies, sessions, flash sessions etc. but don't rely on $this->request->getHTTPReferer() containing any value.



12.6k

actually I need the ACTUAL url right now, not the one where the user came from



12.0k
edited Oct '15

I see. Try using router like this $this->router->getRewriteUri()

Of course you could always use plain php to get complete url with query - something like 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] forum has screwed up the code, but you get the idea :)