Jump to content


Photo

$_COOKIE question


  • Please log in to reply
4 replies to this topic

#1 tjhilder

tjhilder
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationKent, UK

Posted 19 March 2006 - 11:07 AM

Hi,

til now I've been using $_SESSION but I want to change it to $_COOKIE so that the user's login doesn't expire when the browser is closed.

right now I have it like

$_SESSION['member_id'] = $row[0];

etc, was wondering if it would be a case of doing it like

$member_id_cookie = $row[0];
setcookie("site_member_id", $member_id_cookie, time()+3600, "/", ".mysite.com", 1);

then I'd find the info by changing this:

if (isset($_SESSION['member_id']))
{
    if ($_SESSION['something_else'] <= 4) 
        {

to:

if (isset($_COOKIE['site_member_id'])) 
{
    if ($_COOKIE['something_else'] <= 4) 
        {

would this work? if not, if you could give me some info that would help me that would be great!

thanks in advance.

TJ

#2 tjhilder

tjhilder
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationKent, UK

Posted 20 March 2006 - 06:59 AM

anyone?

#3 TEENFRONT

TEENFRONT
  • Members
  • PipPipPip
  • Advanced Member
  • 338 posts

Posted 20 March 2006 - 07:38 AM

im no cookie expert,

but it looks good enough to me, instead of asking if it would work, why dont ya give it a quick whirl, then if it doesnt work, ask for help :)
Teenfront.co.uk : Free Teen Chat -  FunkySmileys.co.uk : MSN Smileys -  ArcadeMonkey.co.uk : Free Flash Games
8Baller.co.uk : Free Multiplayer Pool [url=http://8Baller.co.uk]

#4 tjhilder

tjhilder
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationKent, UK

Posted 23 March 2006 - 05:51 PM

ok so I tried doing that, ran it, and nothing happened, no cookies stored.

                $username_cookie = $row[1];
                $member_id_cookie = $row[0];
                $rank_cookie = $row[3];
                setcookie("v3_user", $username_cookie, time()+3600, "/", "www.tjhilder.co.uk", 1);
                setcookie("v3_id", $member_id_cookie, time()+3600, "/", "www.tjhilder.co.uk", 1);
                setcookie("v3_rank", $rank_cookie, time()+3600, "/", "www.tjhilder.co.uk", 1);

any ideas?

#5 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 23 March 2006 - 06:05 PM

ultimately, totally replacing $_SESSION with $_COOKIE is floored. not saying it wouldnt work, but for some it wouldnt.
imagine if a user had cookies turned off....

the best way to keep a user logged in would be a bit of a mix of both methods. carry on using sessions, but when the user logs on, set the relevent cookies if they choose to (via a 'remember me' box or something).

the easiest way then would be to use the cookie info instead of presenting the login page. just make sure that when 'logout' is used that the cookies are also destroyed.

at least this way, users who have cookies turned off will still be able to use your site.

cheers
Mark
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users