php session cookie life time problem

最近學緊PHP, 學到cookie 同session 有D唔明白

如果整user login, login成功後, 我set 左兩個session,
$_SESSION['login'] = true;
$_SESSION['username'] = $username;
但係每次close左個browser之後, 再入番去就當我未login, 我check 番 session 個file, 多左一個出黎,
我想咪呢個係咪正確

如果我想做到google 果個效果,  close 左browser之後, 再入番去都仲係login左,   
應該點做法?

cookies

TOP

google 用cookie identify user有冇login?

TOP

本帖最後由 神秘二代 於 2014-10-21 23:41 編輯
google 用cookie identify user有冇login?
twaiho2003 發表於 2014-10-21 23:29


when user login, generate unit code (token), store at server (db) and client (cookie)
next time compare the code, if not match, redirect to login page

TOP

回覆 4# 神秘二代


    how to get back my previous session instead of create a new one

TOP

回覆  神秘二代


    how to get back my previous session instead of create a new one
twaiho2003 發表於 2014-10-21 23:48


session not designed for store the data
session for temporary storage only......

but if you want to get back...you can through the session id
  1. $sessionid = 'session id stored at client/ you know the session id';
  2. session_start($sessionid);
複製代碼
i think the effect same as cookie....because finally you need save something at client side= =....

TOP

回覆 6# 神秘二代


    thanks, I just find the solution
add
$lifeTime = 24 * 3600;
session_set_cookie_params($lifeTime);

before the first session_start(); statement

TOP

本帖最後由 twaiho2003 於 2014-10-22 01:20 編輯

又有新問題,個SESSION 唔識自己DEL ,佢本身係1440(24分鐘),我SET做40之後RESTART SERVER,個SESSION等左40秒都唔DEL

已解決,原來有 session.gc_maxlifetime,session.gc_divisor,session.gc_probability 影響個SESSION幾時自動DEL

TOP