Jump to content

$_COOKIE question


tjhilder

Recommended Posts

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

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

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

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

then I'd find the info by changing this:

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

to:

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

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

thanks in advance.

TJ
Link to comment
Share on other sites

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

[code]
                $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);
[/code]

any ideas?
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.