# uniq in the server. $sid = msession_uniq(32); setcookie ("PHPSESSID", $sid); session_id($sid); $HTTP_COOKIE_VARS["PHPSESSID"] = $sid; # New session, set some variables if(0) // One at a time { echo "Set Variable: " . msession_set($sid, 'time',time()) ."<p>\n"; echo "Set Variable: " . msession_set($sid, 'name1','test1') ."<p>\n"; echo "Set Variable: " . msession_set($sid, 'name2','test2') ."<p>\n"; echo "Set Variable: " . msession_set($sid, 'name3','test3') ."<p>\n"; echo "Set Variable: " . msession_set($sid, 'name4','test4') ."<p>\n"; echo "Set Variable: " . msession_set($sid, 'name5','test5') ."<p>\n"; echo "Set Variable: " . msession_set($sid, 'name6','test6') ."<p>\n"; echo "Set Variable: " . msession_set($sid, 'name7','test7') ."<p>\n"; } else // All at once in an array { $setarray = array(); $setarray['time']=time(); $setarray['name1'] = 'test1'; $setarray['name2'] = 'test2'; $setarray['name3'] = 'test3'; $setarray['name4'] = 'test4'; $setarray['name5'] = 'test5'; $setarray['name6'] = 'test6'; $setarray['name7'] = 'test7'; msession_set_array($sid, $setarray); } }
/** * Stores a dataset. * * WARNING: If you supply userdata it must not contain any linebreaks, * otherwise it will break the filestructure. */ function save($id, $cachedata, $expires, $group, $userdata) { $this->flushPreload($id, $group); $cachedata = $this->encode($cachedata); $expires_abs = $this->getExpiresAbsolute($expires); $size = 1 + strlen($cachedata) + strlen($expires_abs) + strlen($userdata) + strlen($group); $size += strlen($size); $data = array('cachedata' => $cachedata, 'expires' => $expires_abs, 'userdata' => $userdata); $id = strtoupper(md5($group)) . $id; msession_lock($id); if (!msession_set($id, '_pear_cache', true)) { msession_unlock($id); return new Cache_Error("Can't write cache data.", __FILE__, __LINE__); } if (!msession_set($id, '_pear_cache_data', $data)) { msession_unlock($id); return new Cache_Error("Can't write cache data.", __FILE__, __LINE__); } if (!msession_set($id, '_pear_cache_group', $group)) { msession_unlock($id); return new Cache_Error("Can't write cache data.", __FILE__, __LINE__); } if (!msession_set($id, '_pear_cache_size', $size)) { msession_unlock($id); return new Cache_Error("Can't write cache data.", __FILE__, __LINE__); } // let msession do some GC as well // note that msession works different from the PEAR Cache. // msession deletes an entry if it has not been used for n-seconds. // PEAR Cache deletes after n-seconds. if (0 != $expires) { msession_timeout($id, $expires); } msession_unlock($id); return true; }