CodeIgniter Forums
Getting the view name of the referring url - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Getting the view name of the referring url (/showthread.php?tid=20204)

Pages: 1 2


Getting the view name of the referring url - El Forum - 07-01-2009

[eluser]adaykin[/eluser]
Hello,

Is there a way that I can get the view name of the referring url? So if the user went from a view named pagex to a view named pagey, how would I know which view the user just came from?


Getting the view name of the referring url - El Forum - 07-01-2009

[eluser]Colin Williams[/eluser]
Sessions


Getting the view name of the referring url - El Forum - 07-01-2009

[eluser]Michael Wales[/eluser]
Sessions is the right direction, to be more specific I believe flashdata would be most appropriate (unless there is an intermediary page).


Getting the view name of the referring url - El Forum - 07-02-2009

[eluser]adaykin[/eluser]
I'm planning on using this on a login page so a user won't have a session yet. Is there any other way I can do this? I assume you need a session to use flashdata correct?


Getting the view name of the referring url - El Forum - 07-02-2009

[eluser]Thorpe Obazee[/eluser]
[quote author="adaykin" date="1246604769"]I'm planning on using this on a login page so a user won't have a session yet.[/quote]

Are you sure about that? Tongue

Another option is to track users' whereabouts via sessions.

Another option is to use this helper from Kohana

Code:
function referrer($default = FALSE)
    {
        if ( ! empty($_SERVER['HTTP_REFERER']))
        {
            $ref = $_SERVER['HTTP_REFERER'];

            if (strpos($ref, base_url()) === 0)
            {
                $ref = substr($ref, strlen(site_url()));
            }
        }

        return isset($ref) ? $ref : $default;
    }



Getting the view name of the referring url - El Forum - 07-02-2009

[eluser]adaykin[/eluser]
Well yeah, if the user hasn't logged in yet they won't have a session yet. So before they log in I need something. After that yeah sessions are what I would use.

I just have been reading about the referrer, and I read that it wasn't secure, so I was wondering if CI did it in a way that was.


Getting the view name of the referring url - El Forum - 07-02-2009

[eluser]Thorpe Obazee[/eluser]
I don't think you get what we mean by Sessions.

e.g. You can store information in sessions. You don't need to be logged into anywhere to have sessions.


Getting the view name of the referring url - El Forum - 07-02-2009

[eluser]adaykin[/eluser]
I know but I would like to avoid using it except for authentication.


Getting the view name of the referring url - El Forum - 07-02-2009

[eluser]Thorpe Obazee[/eluser]
No CI_Sessions or $_SESSIONS, no HTTP_REFERER.

You're probably autoloading the Session Library which already generates session data... why don't you want to use it.. Is there any reason?


Getting the view name of the referring url - El Forum - 07-03-2009

[eluser]Haloperidol[/eluser]
[quote author="adaykin" date="1246613510"]I know but I would like to avoid using it except for authentication.[/quote]

Theres absolutely no reason to not use sessions. Sometimes people confuse it with variables stored in cookies, maybe thats what makes you say that? Just to be sure, when youre using sessions it looks something like this:
1. user connects to your site
2. site checks if the user has a live session associated with him (no need to login or anything, if the user has a live session id the browser transfers it in the http request header)
3. if not, a session is created for the user with a unique id
4. only this id is transferred to the user in a cookie (in the http response header)
5. from now on every $_SESSION ($this->session->userdata or ->flashdata etc) is stored on the server side.

The user has absolutely no control over it (except he can block cookies altogether), cant change nor view the session variables associated with his id, so its safe. Codeigniter also checks for the user agent by default and can be configured to also check for the ip before accepting session ids from a cookie so its quite hard to hijack a session.

As someone already said, youre probably issuing session ids already not even knowing it Smile

Theres a very nice explanation about sessions: http://www.talkphp.com/general/1077-understanding-life-session.html