0

How to detect URL from user came in Codeigniter?

For example, I am at page: /contact/, after click the link with url /news/ at controller news I must detect the previous URL /contact/

Arsen
  • 21
  • 7

1 Answers1

0

You can probably grab the referring page using the PHP $_SERVER array.

See: http://php.net/manual/en/reserved.variables.server.php

Specifically: HTTP_REFERER

You may need to parse the string to get the part that you need.

Marc Audet
  • 46,011
  • 11
  • 63
  • 83
  • 1
    Some browsers may omit this field (private browsing mode, etc.), so don't forget to check for its existence: `if (isset($_SERVER['HTTP_REFERER'])) {...}` – Gras Double Oct 13 '14 at 23:38
  • 1
    **Note :** anybody can spoof it at anytime regardless of whether they clicked on a link or they simply don't sent it at all to begin with. [refrence](http://stackoverflow.com/questions/4662110/how-to-get-the-previous-url-using-php) – Karan Thakkar Oct 14 '14 at 05:13