We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to get full url?

I have this url:

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

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



58.4k
Accepted
answer

Hey

In the controller you just call following

$this->request->getHTTPReferer()


20.4k

$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.



28.2k

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



20.4k
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 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] forum has screwed up the code, but you get the idea :)