SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Accessing Cookie Data

    Hey there,

    I'm trying to implement a "Remember Me" option for a website I'm working on.

    I'm creating the cookie using
    Code:
    cookie = CGI::Cookie.new("name" => "logged_in", "value"=> somedata, "expires" => (Time.now + 30.days))
    response.headers["cookie"] << cookie
    This creates the cookie fine.
    How would I go about checking to see if the cookie is there, though??

    Thanks in advance.

  2. #2
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you using Rails?

    Then you can do this:

    Code:
    cookies[:logged_in]
    to get the value of the cookie.

    EDIT: there is an easier way to set it:

    Code:
    cookies[:logged_in] = {:value => somedata, :expires => Time.now + 30.days}

  3. #3
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Funny... thats exactly what I was trying to do last night but it wasn't working. But what do ya know, it works perfectly now!!!

    Thanks for the tip on setting it, that looks a lot nicer =)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •