Flash vs session vs globale variable for storing referrer

In creating my app, Im trying to figure out the best way to save the
page referrer information.

So far I’ve been flashing the referrer information across pages using
flash.keep. Im not using session because I heard that “sessions don’t
scale well” or something like that.

What’s the best way to store the referrer information. Why can’t we just
use a global variable like $url_referrer.

I understand that it isnt good to make global variables, but in this
case, I will just be using it to referrer the user. I just have to make
sure that I set it to the right value for the user.

In any case, its a pain having to flash the variables, if I could just
store one variable that just keeps getting overwritten.

I would love to get anyones thoughts on this. Thanks in advance.

Aryk

Eric G. wrote:

I understand that it isnt good to make global variables, but in this
case, I will just be using it to referrer the user. I just have to make
sure that I set it to the right value for the user.

Not sure I understand completely, but to log the referrer I would do the
following:

  1. detect when a new session is created
  2. if new (first time), log the referrer to referrer_log otherwise do
    nothing

Capturing the referrer at first visit will give you external referrers,
in most cases.
I am assuming you don’t want to log local referrers.

If this is not what you want perhaps you can provide more detail.

Long
www.edgesoft.ca/blog/read/2 - rails articles

On Dec 20, 12:00 pm, Aryk G. [email protected]
wrote:

Can I just use a global variable or a session. I heard sessions dont
scale well though or something like that.

There is nothing wrong with using sessions. They are there to preserve
state for a user between requests and that is exactly what you are
trying to do. The one rule I’ve heard over and over is do not store
ActiveRecord objects in the session, store the objects id instead.

I think it’s always good to ask yourself “do I really need to store
this in the session?”. Setting a session variable can seem like an
easy solution until your application becomes riddled with checks for
various session variables.

Take what you are trying to do with storing the referrer. Do you
really not know where the user is coming from? Do you always want to
send them back to the page they came from? Where do you send them if
the referrer session variable is not set? Maybe you could put a menu
on every page and let the user decide where they want to go next.

Aaron

Long, the scenario I’m refering to (no pun intended) is when I’m running
the user through a series of webpages and at the end, I want to refer
the person back to where they originally came from.

So for example, If I’m viewing an album, and I click on a picture, I
view the pic on a different screen, then if I click “delete” I get taken
to a deletion confirmation screen. Then if the user deletes, it goes
back to the album.

Something like that…

Currently I do stuff like:

flash.keep(:referrer)
flash[:referrer] = flash[:referrer]||request.env[“HTTP_REFERER”]

This is kind of annoying to have to put a method call in every action I
want to keep the referrer in.

Can I just use a global variable or a session. I heard sessions dont
scale well though or something like that.

Long wrote:

Eric G. wrote:

I understand that it isnt good to make global variables, but in this
case, I will just be using it to referrer the user. I just have to make
sure that I set it to the right value for the user.

Not sure I understand completely, but to log the referrer I would do the
following:

  1. detect when a new session is created
  2. if new (first time), log the referrer to referrer_log otherwise do
    nothing

Capturing the referrer at first visit will give you external referrers,
in most cases.
I am assuming you don’t want to log local referrers.

If this is not what you want perhaps you can provide more detail.

Long
www.edgesoft.ca/blog/read/2 - rails articles

The problem with global var is that you only have one place to hold the
:back
pages of multiple users, each could have a different :back page. Every
user will
be directed to the :back page that was last recorded, possibly by
another user.

Long

Oh I c, so the global variables can change between users. Ok, I think I
will just store session[:back]. Of course I will write a function just
in case it is null.

Aaron, to answer your question, I need won’t know where the user is
coming from, he could potentially be coming from a search results page.
Of course, if I know where they are supposed to go back to, then I will
manually input that.

Thanks guys.

Aryk G. wrote:

Long, the scenario I’m refering to (no pun intended) is when I’m running
the user through a series of webpages and at the end, I want to refer
the person back to where they originally came from.

Ah, so the referrer is really local to your site.

So for example, If I’m viewing an album, and I click on a picture, I
view the pic on a different screen, then if I click “delete” I get taken
to a deletion confirmation screen. Then if the user deletes, it goes
back to the album.

Well in this scenario you know exactly what page (album) to bring the
user
back to after a delete. I don’t see any gain in trying to remember where
the user
came from, but that is just my opinion.

You could mark the page where the user should return to in the session.
For
example session[:back] = ‘/album’ when the user enters /album. Though
you will
have to watch out for the case where session[:back] is undefined (it
could happen).

Can I just use a global variable or a session. I heard sessions dont
scale well though or something like that.

I don’t see any problem storing numbers and strings in the session, even
simple
models such as user_profile. It should be fine as long as you don’t
store say
a collection of a particular model.

The problem with global var is that you only have one place to hold the
:back
pages of multiple users, each could have a different :back page. Every
user will
be directed to the :back page that was last recorded, possibly by
another user.

Long