tjhilder Posted March 19, 2006 Share Posted March 19, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/5279-_cookie-question/ Share on other sites More sharing options...
tjhilder Posted March 20, 2006 Author Share Posted March 20, 2006 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/5279-_cookie-question/#findComment-18980 Share on other sites More sharing options...
TEENFRONT Posted March 20, 2006 Share Posted March 20, 2006 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 :) Quote Link to comment https://forums.phpfreaks.com/topic/5279-_cookie-question/#findComment-18982 Share on other sites More sharing options...
tjhilder Posted March 23, 2006 Author Share Posted March 23, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/5279-_cookie-question/#findComment-20035 Share on other sites More sharing options...
redbullmarky Posted March 23, 2006 Share Posted March 23, 2006 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.cheersMark Quote Link to comment https://forums.phpfreaks.com/topic/5279-_cookie-question/#findComment-20042 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.