php: cookie based sessions -


does body have info/links how integrate cookie based session system? i've used file/mysql, , using memcached. wanted play apc sessions, thought i'd give go @ cookies, don't know it.

i imagine i'd have write own session handler class?

in php session data stored in file. thing stored in cookie session identifier. when sessions enabled , valid session cookie found, php loads users session data file super global called funnily enough session.

basic sessions started using session_start(); called before text sent browser. items added or removed session object using simple array indexing eg.

$_session['favcolour'] = 'blue';  

later...

$favcolour = $_session['favcolour']; 

basic cookie sessions (no local storage) can created call to

 set_cookie('favcolour','blue'[,other params]); 

before text sent browser, retrieved cookie superglobal

$favcolour = $_cookie['favcolour']; 

you don't need call session_start() if doing cookie sessions.

the optional [,other params] more advanced , can read here http://www.php.net/manual/en/function.setcookie.php

sessions can become complex discussion, i'd suggest doing light work in them , expand knowledge.

dc

all ever wanted know php sessions

http://www.php.net/manual/en/book.session.php

dc

to reuse php's session handling code need add write handler using session_set_save_handler , nothing in handler. that's because called after output browser closed therefore cannot send browser.

before writing non header data browser use set_cookie functions , store contents of $_session array (after serialising , encrypting) cookie. when applications start can read cookie unserialise , put $_session array.

that's quick hint @ have never done it, prefer write own cookie code. there may gotcha's not hard few tests should find gotcha's.

dc


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -