function CloseSessionIfEmpty() { $encoded = @session_encode(); if (false !== $encoded && 0 == strlen($encoded)) { session_destroy(); } }
public function buildFiles() { $ess_usronline = new ess_usronline(); $ess_usronline->query('DELETE FROM ess_usronline'); $datSesAct = session_encode(); $d = dir($session_path = session_save_path()); while (false !== ($entry = $d->read())) { $session_file_name = $session_path . '/' . $entry; if (is_readable($session_file_name)) { if (is_file($session_file_name)) { $arVarSes = array(); $filesize = filesize($session_file_name); if ($filesize > 20) { $_SESSION['datetime'] = $_SESSION['ip'] = $_SESSION['user_id'] = ''; $cont = ''; $f = fopen($session_file_name, 'r'); $cont = fread($f, $filesize); fclose($f); session_decode($cont); if ($_SESSION['user_id'] != "") { $ess_usronline->usuario_id = $_SESSION['user_id']; $ess_usronline->ip = $_SESSION['ip']; $ess_usronline->sesname = $entry; $ess_usronline->size = intval($filesize / 1024); $ess_usronline->filectime = date("Y-m-d H:i:s", filectime($session_file_name)); $ess_usronline->datetime = $_SESSION['datetime']; $ess_usronline->save(); } } session_decode($datSesAct); } } } $d->close(); }
function mysql_session_read($SID) { $ip = $_SERVER['REMOTE_ADDR']; $sql = "\n SELECT data,refresh,playerid \n FROM l_session \n WHERE id = '{$SID}' \n and expire > now() \n "; $res = mysql_query($sql); if ($res) { $row = mysql_fetch_assoc($res); if ($row) { $session = stripslashes($row['data']); if ($row['refresh'] == 'Y' and !empty($row['playerid'])) { $_SESSION = unserialize_session_data($session); session_data_reload($row['playerid']); $session = session_encode(); unset($_SESSION); $sql = "UPDATE l_session SET refresh='N' WHERE id='{$SID}'"; mysql_query($sql); } return $session; } else { mysql_session_destroy($SID); } } sessionStaticInfo(); return ""; }
function PrintPageHeader() { global $DBtype, $ADODB_vers; $tmp = session_encode(); $php_version = phpversion(); $ver = $php_version[0]; $request_uri = XSSPrintSafe($_SERVER['REQUEST_URI']); if ($ver >= 5 || $ver == 4 && $php_version[1] >= 1) { if (array_key_exists("HTTP_REFERER", $_SERVER)) { $http_referer = XSSPrintSafe($_SERVER['HTTP_REFERER']); } else { $http_referer = ""; } } else { if (key_exists("HTTP_REFERER", $_SERVER)) { $http_referer = XSSPrintSafe($_SERVER['HTTP_REFERER']); } else { $http_referer = ""; } } $http_user_agent = XSSPrintSafe($_SERVER['HTTP_USER_AGENT']); $server_software = XSSPrintSafe($_SERVER['SERVER_SOFTWARE']); $query_string = XSSPrintSafe($_SERVER['QUERY_STRING']); echo "<PRE>\n <B>URL:</B> '" . $request_uri . "'\n (<B>referred by:</B> '" . $http_referer . "')\n <B>PARAMETERS:</B> '" . $query_string . "'\n <B>CLIENT:</B> " . $http_user_agent . "\n <B>SERVER:</B> " . $server_software . "\n <B>SERVER HW:</B> " . php_uname() . "\n <B>DATABASE TYPE:</B> {$DBtype} <B>DB ABSTRACTION VERSION:</B> {$ADODB_vers}\n <B>PHP VERSION:</B> " . phpversion() . " <B>PHP API:</B> " . php_sapi_name() . "\n <B>BASE VERSION:</B> " . $GLOBALS['BASE_VERSION'] . "\n <B>SESSION ID:</B> " . session_id() . "( " . strlen($tmp) . " bytes )\n </PRE>"; }
/** * Read session data * * @param string $id * @return string */ public function read($id) { $_SESSION = json_decode($this->memcached->get("sessions/{$id}"), true); if (isset($_SESSION) && !empty($_SESSION) && $_SESSION != null) { return session_encode(); } return ''; }
/** * Returns a cloned session id * * This feature enables session data cloning, and is useful when you want to call scripts using * localhost keeping your actual session opened. * * What is done by cloneSid : * - a new session id is registered * - the new session file is immediately created with the data of the current session * * @return string the cloned session id */ public static function cloneSessionId() { $old_id = session_id(); session_regenerate_id(); $new_id = session_id(); file_put_contents(session_save_path() . SL . 'sess_' . $new_id, session_encode()); session_id($old_id); return $new_id; }
public function testSessionWrite() { $_SESSION['test'] = "some string"; $_SESSION['mongo'] = "Cool DB!"; $expected = session_encode(); session_write_close(); $database = $this->mongo->selectDB("session"); $sessions = $database->selectCollection("session"); // Only select the session data with id = session_id() $data = $sessions->findOne(array('session_id' => session_id()), array('data')); $this->assertEquals($expected, $data['data']); }
/** * Read the id * @param string $id The SESSID to search for * @return string The session saved previously */ public function read($id) { $tmp = $_SESSION; $_SESSION = json_decode($this->memcache->get("sessions/{$id}"), true); if (isset($_SESSION) && !empty($_SESSION) && $_SESSION != null) { $new_data = session_encode(); $_SESSION = $tmp; return $new_data; } else { return ""; } }
public function close() { $rid = rand(); // addtologEx ('session', $rid.' saving session file '.$this->savePath."/sess_".$this->id); $data = session_encode(); if ($data) { file_put_contents($this->savePath.'/sess_'.$this->id, $data); } // addtologEx ('session', $rid.' data: '.print_r($data,true)); // echo "close"; return true; }
/** * Gets json_encoded Session data from Redis * and encode it back to php's session encoding */ public function read($id) { $tmp = $_SESSION; $id = $this->redisKeyPath() . $id; $_SESSION = json_decode($this->client->get($id), true); $this->client->expire($id, $this->ttl); if (isset($_SESSION) && !empty($_SESSION) && $_SESSION != null) { $new_data = session_encode(); $_SESSION = $tmp; return $new_data; } else { return ""; } }
function session_clear() { // if session exists, unregister all variables that exist and destroy session $exists = "no"; $session_array = explode(";", session_encode()); for ($x = 0; $x < count($session_array); $x++) { $name = substr($session_array[$x], 0, strpos($session_array[$x], "|")); if (session_is_registered($name)) { session_unregister('$name'); $exists = "yes"; } } if ($exists != "no") { session_destroy(); } }
/** * @runInSeparateProcess */ public function testReadWrite() { session_start(); $saveHandler = new Memcached($this->memcached); $this->assertTrue($saveHandler->open('savepath', 'sessionname')); $id = session_id(); $_SESSION = array('foo' => 'bar', 'bar' => array('foo' => 'bar')); $this->assertTrue($saveHandler->write($id, session_encode())); $this->assertEquals($_SESSION, json_decode($this->memcached->get("sessions/{$id}"), true)); $serializedSession = $saveHandler->read($id); $this->assertTrue(!empty($serializedSession)); $_SESSION = array('foo' => array(1, 2, 3)); $this->assertTrue($saveHandler->write($id, serialize($_SESSION))); $this->assertEquals($_SESSION, json_decode($this->memcached->get("sessions/{$id}"), true)); $serializedSession2 = $saveHandler->read($id); $this->assertTrue(!empty($serializedSession2)); }
function processLogout() { if (!checkSession()) { return; } // Reset Session Values $_SESSION['adminAuth'] = ''; $_SESSION['adminTime'] = ''; // If session exists, unregister all variables that exist and destroy session $exists = false; $session_array = explode(";", session_encode()); for ($x = 0; $x < count($session_array); $x++) { $name = substr($session_array[$x], 0, strpos($session_array[$x], "|")); if (session_is_registered($name)) { session_unregister('$name'); $exists = true; } } if ($exists) { session_destroy(); } }
public function Start() { if ($this->getIsSessionStarted(true)) { return; } $request_type = getenv('HTTPS') == 'on' ? 'SSL' : 'NONSSL'; // set the cookie domain $cookie_domain = $request_type == 'NONSSL' ? \src\classes\Environment::HTTP_COOKIE_DOMAIN : \src\classes\Environment::HTTPS_COOKIE_DOMAIN; $cookie_path = $request_type == 'NONSSL' ? \src\classes\Environment::HTTP_COOKIE_PATH : \src\classes\Environment::HTTPS_COOKIE_PATH; $currentSession = null; // set the session cookie parameters if (function_exists('session_set_cookie_params')) { session_set_cookie_params(0, $cookie_path, $cookie_domain); } elseif (function_exists('ini_set')) { ini_set('session.cookie_lifetime', '0'); ini_set('session.cookie_path', $cookie_path); ini_set('session.cookie_domain', $cookie_domain); } $sessionId = isset($_COOKIE['sessionId']) ? $_COOKIE['sessionId'] : md5(uniqid(rand(), true)); if (!isset($_COOKIE['sessionId'])) { setcookie('sessionId', $sessionId, time() + 60 * 60 * 24); } else { session_id($sessionId); session_start(); $currentSession = session_encode(); session_destroy(); $sessionId = md5(uniqid(rand(), true)); setcookie('sessionId', $sessionId, time() + 60 * 60 * 24); } session_id($sessionId); session_start(); if ($currentSession !== null) { session_decode($currentSession); } $hasCookies = false; $this->setIsSessionStarted(true); $this->RegisterVariable('sessionId', $sessionId); }
function session_close() { global $session, $SID; if ($session->nr_open_sessions == 0) { return false; } // Encode session $val = session_encode(); $len = strlen($val); // Save session $mod = $GLOBALS[$session->mod_name]; if (!$mod->write($session->id, $val)) { die('Session could not be saved.'); } // Close session if (function_exists($session->mod_name . '->close') && !$mod->close()) { die('Session could not be closed.'); } $SID = ''; $session->nr_open_sessions--; return true; }
<?php ob_start(); /* * Prototype : string session_encode(void) * Description : Encodes the current session data as a string * Source code : ext/session/session.c */ echo "*** Testing session_encode() : variation ***\n"; var_dump(session_start()); $_SESSION["foo"] = 1234567890; $encoded = session_encode(); var_dump(base64_encode($encoded)); var_dump(session_destroy()); echo "Done"; ob_end_flush();
/** * get_performance_info() pairs up with init_performance_info() * loaded in setup.php. Returns an array with 'html' and 'txt' * values ready for use, and each of the individual stats provided * separately as well. * * @global object * @global object * @global object * @return array */ function get_performance_info() { global $CFG, $PERF, $DB, $PAGE; $info = array(); $info['html'] = ''; // holds userfriendly HTML representation $info['txt'] = me() . ' '; // holds log-friendly representation $info['realtime'] = microtime_diff($PERF->starttime, microtime()); $info['html'] .= '<span class="timeused">' . $info['realtime'] . ' secs</span> '; $info['txt'] .= 'time: ' . $info['realtime'] . 's '; if (function_exists('memory_get_usage')) { $info['memory_total'] = memory_get_usage(); $info['memory_growth'] = memory_get_usage() - $PERF->startmemory; $info['html'] .= '<span class="memoryused">RAM: ' . display_size($info['memory_total']) . '</span> '; $info['txt'] .= 'memory_total: ' . $info['memory_total'] . 'B (' . display_size($info['memory_total']) . ') memory_growth: ' . $info['memory_growth'] . 'B (' . display_size($info['memory_growth']) . ') '; } if (function_exists('memory_get_peak_usage')) { $info['memory_peak'] = memory_get_peak_usage(); $info['html'] .= '<span class="memoryused">RAM peak: ' . display_size($info['memory_peak']) . '</span> '; $info['txt'] .= 'memory_peak: ' . $info['memory_peak'] . 'B (' . display_size($info['memory_peak']) . ') '; } $inc = get_included_files(); //error_log(print_r($inc,1)); $info['includecount'] = count($inc); $info['html'] .= '<span class="included">Included ' . $info['includecount'] . ' files</span> '; $info['txt'] .= 'includecount: ' . $info['includecount'] . ' '; $filtermanager = filter_manager::instance(); if (method_exists($filtermanager, 'get_performance_summary')) { list($filterinfo, $nicenames) = $filtermanager->get_performance_summary(); $info = array_merge($filterinfo, $info); foreach ($filterinfo as $key => $value) { $info['html'] .= "<span class='{$key}'>{$nicenames[$key]}: {$value} </span> "; $info['txt'] .= "{$key}: {$value} "; } } $stringmanager = get_string_manager(); if (method_exists($stringmanager, 'get_performance_summary')) { list($filterinfo, $nicenames) = $stringmanager->get_performance_summary(); $info = array_merge($filterinfo, $info); foreach ($filterinfo as $key => $value) { $info['html'] .= "<span class='{$key}'>{$nicenames[$key]}: {$value} </span> "; $info['txt'] .= "{$key}: {$value} "; } } $jsmodules = $PAGE->requires->get_loaded_modules(); if ($jsmodules) { $yuicount = 0; $othercount = 0; $details = ''; foreach ($jsmodules as $module => $backtraces) { if (strpos($module, 'yui') === 0) { $yuicount += 1; } else { $othercount += 1; } $details .= "<div class='yui-module'><p>{$module}</p>"; foreach ($backtraces as $backtrace) { $details .= "<div class='backtrace'>{$backtrace}</div>"; } $details .= '</div>'; } $info['html'] .= "<span class='includedyuimodules'>Included YUI modules: {$yuicount}</span> "; $info['txt'] .= "includedyuimodules: {$yuicount} "; $info['html'] .= "<span class='includedjsmodules'>Other JavaScript modules: {$othercount}</span> "; $info['txt'] .= "includedjsmodules: {$othercount} "; // Slightly odd to output the details in a display: none div. The point // Is that it takes a lot of space, and if you care you can reveal it // using firebug. $info['html'] .= '<div id="yui-module-debug" class="notifytiny">' . $details . '</div>'; } if (!empty($PERF->logwrites)) { $info['logwrites'] = $PERF->logwrites; $info['html'] .= '<span class="logwrites">Log DB writes ' . $info['logwrites'] . '</span> '; $info['txt'] .= 'logwrites: ' . $info['logwrites'] . ' '; } $info['dbqueries'] = $DB->perf_get_reads() . '/' . ($DB->perf_get_writes() - $PERF->logwrites); $info['html'] .= '<span class="dbqueries">DB reads/writes: ' . $info['dbqueries'] . '</span> '; $info['txt'] .= 'db reads/writes: ' . $info['dbqueries'] . ' '; if (!empty($PERF->profiling) && $PERF->profiling) { require_once $CFG->dirroot . '/lib/profilerlib.php'; $info['html'] .= '<span class="profilinginfo">' . Profiler::get_profiling(array('-R')) . '</span>'; } if (function_exists('posix_times')) { $ptimes = posix_times(); if (is_array($ptimes)) { foreach ($ptimes as $key => $val) { $info[$key] = $ptimes[$key] - $PERF->startposixtimes[$key]; } $info['html'] .= "<span class=\"posixtimes\">ticks: {$info['ticks']} user: {$info['utime']} sys: {$info['stime']} cuser: {$info['cutime']} csys: {$info['cstime']}</span> "; $info['txt'] .= "ticks: {$info['ticks']} user: {$info['utime']} sys: {$info['stime']} cuser: {$info['cutime']} csys: {$info['cstime']} "; } } // Grab the load average for the last minute // /proc will only work under some linux configurations // while uptime is there under MacOSX/Darwin and other unices if (is_readable('/proc/loadavg') && ($loadavg = @file('/proc/loadavg'))) { list($server_load) = explode(' ', $loadavg[0]); unset($loadavg); } else { if (function_exists('is_executable') && is_executable('/usr/bin/uptime') && ($loadavg = `/usr/bin/uptime`)) { if (preg_match('/load averages?: (\\d+[\\.,:]\\d+)/', $loadavg, $matches)) { $server_load = $matches[1]; } else { trigger_error('Could not parse uptime output!'); } } } if (!empty($server_load)) { $info['serverload'] = $server_load; $info['html'] .= '<span class="serverload">Load average: ' . $info['serverload'] . '</span> '; $info['txt'] .= "serverload: {$info['serverload']} "; } // Display size of session if session started if (session_id()) { $info['sessionsize'] = display_size(strlen(session_encode())); $info['html'] .= '<span class="sessionsize">Session: ' . $info['sessionsize'] . '</span> '; $info['txt'] .= "Session: {$info['sessionsize']} "; } /* if (isset($rcache->hits) && isset($rcache->misses)) { $info['rcachehits'] = $rcache->hits; $info['rcachemisses'] = $rcache->misses; $info['html'] .= '<span class="rcache">Record cache hit/miss ratio : '. "{$rcache->hits}/{$rcache->misses}</span> "; $info['txt'] .= 'rcache: '. "{$rcache->hits}/{$rcache->misses} "; }*/ $info['html'] = '<div class="performanceinfo siteinfo">' . $info['html'] . '</div>'; return $info; }
/** * Get current Session Data * * @return string * Encoded Session Data */ public function getSessionData() { return session_encode(); }
/** * Returns current page performance info. * * @return array perf info */ public static function get_performance_info() { if (!session_id()) { return array(); } self::load_handler(); $size = display_size(strlen(session_encode())); $handler = get_class(self::$handler); $info = array(); $info['size'] = $size; $info['html'] = "<span class=\"sessionsize\">Session ({$handler}): {$size}</span> "; $info['txt'] = "Session ({$handler}): {$size} "; return $info; }
// original comment or credit authors. // // // // This program is distributed in the hope that it will be useful, // // but WITHOUT ANY WARRANTY; without even the implied warranty of // // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // // GNU General Public License for more details. // // // // You should have received a copy of the GNU General Public License // // along with this program; if not, write to the Free Software // // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // ------------------------------------------------------------------------- // error_reporting(0); include 'include/common.inc.php'; $session = session_id(); $sess_handler =& xoops_gethandler('session'); if ($sess_handler->write($session, session_encode())) { $_SESSION['XNPSID'] = $session; } include_once 'include/lib.php'; include_once 'include/AL.php'; include_once 'class/base/oaipmh.class.php'; // retrieve admin's e-mail $emails = array(); $member_handler =& xoops_gethandler('member'); $members = $member_handler->getUsersByGroup(XOOPS_GROUP_ADMIN, false); foreach ($members as $userid) { $user =& $member_handler->getUser($userid); $emails[] = $user->getVar('email'); } $xconfig_handler =& xoonips_getormhandler('xoonips', 'config'); $repositoryName = $xconfig_handler->getValue('repository_name');
/** * get_performance_info() pairs up with init_performance_info() * loaded in setup.php. Returns an array with 'html' and 'txt' * values ready for use, and each of the individual stats provided * separately as well. * * @global object * @global object * @global object * @return array */ function get_performance_info() { global $CFG, $PERF, $DB, $PAGE; $info = array(); $info['html'] = ''; // holds userfriendly HTML representation $info['txt'] = me() . ' '; // holds log-friendly representation $info['realtime'] = microtime_diff($PERF->starttime, microtime()); $info['html'] .= '<span class="timeused">' . $info['realtime'] . ' secs</span> '; $info['txt'] .= 'time: ' . $info['realtime'] . 's '; if (function_exists('memory_get_usage')) { $info['memory_total'] = memory_get_usage(); $info['memory_growth'] = memory_get_usage() - $PERF->startmemory; $info['html'] .= '<span class="memoryused">RAM: ' . display_size($info['memory_total']) . '</span> '; $info['txt'] .= 'memory_total: ' . $info['memory_total'] . 'B (' . display_size($info['memory_total']) . ') memory_growth: ' . $info['memory_growth'] . 'B (' . display_size($info['memory_growth']) . ') '; } if (function_exists('memory_get_peak_usage')) { $info['memory_peak'] = memory_get_peak_usage(); $info['html'] .= '<span class="memoryused">RAM peak: ' . display_size($info['memory_peak']) . '</span> '; $info['txt'] .= 'memory_peak: ' . $info['memory_peak'] . 'B (' . display_size($info['memory_peak']) . ') '; } $inc = get_included_files(); //error_log(print_r($inc,1)); $info['includecount'] = count($inc); $info['html'] .= '<span class="included">Included ' . $info['includecount'] . ' files</span> '; $info['txt'] .= 'includecount: ' . $info['includecount'] . ' '; if (!empty($CFG->early_install_lang) or empty($PAGE)) { // We can not track more performance before installation or before PAGE init, sorry. return $info; } $filtermanager = filter_manager::instance(); if (method_exists($filtermanager, 'get_performance_summary')) { list($filterinfo, $nicenames) = $filtermanager->get_performance_summary(); $info = array_merge($filterinfo, $info); foreach ($filterinfo as $key => $value) { $info['html'] .= "<span class='{$key}'>{$nicenames[$key]}: {$value} </span> "; $info['txt'] .= "{$key}: {$value} "; } } $stringmanager = get_string_manager(); if (method_exists($stringmanager, 'get_performance_summary')) { list($filterinfo, $nicenames) = $stringmanager->get_performance_summary(); $info = array_merge($filterinfo, $info); foreach ($filterinfo as $key => $value) { $info['html'] .= "<span class='{$key}'>{$nicenames[$key]}: {$value} </span> "; $info['txt'] .= "{$key}: {$value} "; } } $jsmodules = $PAGE->requires->get_loaded_modules(); if ($jsmodules) { $yuicount = 0; $othercount = 0; $details = ''; foreach ($jsmodules as $module => $backtraces) { if (strpos($module, 'yui') === 0) { $yuicount += 1; } else { $othercount += 1; } if (!empty($CFG->yuimoduledebug)) { // hidden feature for developers working on YUI module infrastructure $details .= "<div class='yui-module'><p>{$module}</p>"; foreach ($backtraces as $backtrace) { $details .= "<div class='backtrace'>{$backtrace}</div>"; } $details .= '</div>'; } } $info['html'] .= "<span class='includedyuimodules'>Included YUI modules: {$yuicount}</span> "; $info['txt'] .= "includedyuimodules: {$yuicount} "; $info['html'] .= "<span class='includedjsmodules'>Other JavaScript modules: {$othercount}</span> "; $info['txt'] .= "includedjsmodules: {$othercount} "; if ($details) { $info['html'] .= '<div id="yui-module-debug" class="notifytiny">' . $details . '</div>'; } } if (!empty($PERF->logwrites)) { $info['logwrites'] = $PERF->logwrites; $info['html'] .= '<span class="logwrites">Log DB writes ' . $info['logwrites'] . '</span> '; $info['txt'] .= 'logwrites: ' . $info['logwrites'] . ' '; } $info['dbqueries'] = $DB->perf_get_reads() . '/' . ($DB->perf_get_writes() - $PERF->logwrites); $info['html'] .= '<span class="dbqueries">DB reads/writes: ' . $info['dbqueries'] . '</span> '; $info['txt'] .= 'db reads/writes: ' . $info['dbqueries'] . ' '; $info['dbtime'] = round($DB->perf_get_queries_time(), 5); $info['html'] .= '<span class="dbtime">DB queries time: ' . $info['dbtime'] . ' secs</span> '; $info['txt'] .= 'db queries time: ' . $info['dbtime'] . 's '; if (function_exists('posix_times')) { $ptimes = posix_times(); if (is_array($ptimes)) { foreach ($ptimes as $key => $val) { $info[$key] = $ptimes[$key] - $PERF->startposixtimes[$key]; } $info['html'] .= "<span class=\"posixtimes\">ticks: {$info['ticks']} user: {$info['utime']} sys: {$info['stime']} cuser: {$info['cutime']} csys: {$info['cstime']}</span> "; $info['txt'] .= "ticks: {$info['ticks']} user: {$info['utime']} sys: {$info['stime']} cuser: {$info['cutime']} csys: {$info['cstime']} "; } } // Grab the load average for the last minute // /proc will only work under some linux configurations // while uptime is there under MacOSX/Darwin and other unices if (is_readable('/proc/loadavg') && ($loadavg = @file('/proc/loadavg'))) { list($server_load) = explode(' ', $loadavg[0]); unset($loadavg); } else { if (function_exists('is_executable') && is_executable('/usr/bin/uptime') && ($loadavg = `/usr/bin/uptime`)) { if (preg_match('/load averages?: (\\d+[\\.,:]\\d+)/', $loadavg, $matches)) { $server_load = $matches[1]; } else { trigger_error('Could not parse uptime output!'); } } } if (!empty($server_load)) { $info['serverload'] = $server_load; $info['html'] .= '<span class="serverload">Load average: ' . $info['serverload'] . '</span> '; $info['txt'] .= "serverload: {$info['serverload']} "; } // Display size of session if session started if (session_id()) { $info['sessionsize'] = display_size(strlen(session_encode())); $info['html'] .= '<span class="sessionsize">Session: ' . $info['sessionsize'] . '</span> '; $info['txt'] .= "Session: {$info['sessionsize']} "; } if ($stats = cache_helper::get_stats()) { $html = '<span class="cachesused">'; $html .= '<span class="cache-stats-heading">Caches used (hits/misses/sets)</span>'; $text = 'Caches used (hits/misses/sets): '; $hits = 0; $misses = 0; $sets = 0; foreach ($stats as $definition => $stores) { $html .= '<span class="cache-definition-stats">'; $html .= '<span class="cache-definition-stats-heading">' . $definition . '</span>'; $text .= "{$definition} {"; foreach ($stores as $store => $data) { $hits += $data['hits']; $misses += $data['misses']; $sets += $data['sets']; if ($data['hits'] == 0 and $data['misses'] > 0) { $cachestoreclass = 'nohits'; } else { if ($data['hits'] < $data['misses']) { $cachestoreclass = 'lowhits'; } else { $cachestoreclass = 'hihits'; } } $text .= "{$store}({$data['hits']}/{$data['misses']}/{$data['sets']}) "; $html .= "<span class=\"cache-store-stats {$cachestoreclass}\">{$store}: {$data['hits']} / {$data['misses']} / {$data['sets']}</span>"; } $html .= '</span>'; $text .= '} '; } $html .= "<span class='cache-total-stats'>Total: {$hits} / {$misses} / {$sets}</span>"; $html .= '</span> '; $info['cachesused'] = "{$hits} / {$misses} / {$sets}"; $info['html'] .= $html; $info['txt'] .= $text . '. '; } else { $info['cachesused'] = '0 / 0 / 0'; $info['html'] .= '<span class="cachesused">Caches used (hits/misses/sets): 0/0/0</span>'; $info['txt'] .= 'Caches used (hits/misses/sets): 0/0/0 '; } $info['html'] = '<div class="performanceinfo siteinfo">' . $info['html'] . '</div>'; return $info; }
list($thisSessData) = mysqli_fetch_row($result); $t->is(mysqli_num_rows($result), 1, 'session is stored in the database'); $t->is($thisSessData, $session_data, 'session variables are stored in the database'); mysqli_free_result($result); unset($thisSessData, $result); // sessionRead() try { $retrieved_data = $storage->sessionRead($session_id); $t->pass('sessionRead() does not throw an exception'); } catch (Exception $e) { $t->fail('sessionRead() does not throw an exception'); } $t->is($retrieved_data, $session_data, 'sessionRead() reads session data'); // sessionWrite() $_SESSION['baz'] = 'woo'; $session_data = session_encode(); try { $write = $storage->sessionWrite($session_id, $session_data); $t->pass('sessionWrite() does not throw an exception'); } catch (Exception $e) { $t->fail('sessionWrite() does not throw an exception'); } $t->ok($write, 'sessionWrite() returns true'); $t->is($storage->sessionRead($session_id), $session_data, 'sessionWrite() wrote session data'); // sessionDestroy() try { $storage->sessionDestroy($session_id); $t->pass('sessionDestroy() does not throw an exception'); } catch (Exception $e) { $t->fail('sessionDestroy() does not throw an exception'); }
public function torchCartInSession($sessionID) { $rslt = tep_db_query("select value from " . TABLE_SESSIONS . " where sesskey = '" . tep_db_input($sessionID) . "'"); if (tep_db_num_rows($rslt)) { $sessionData = tep_db_fetch_array($rslt); session_id($sessionID); session_start(); unset($_SESSION['cart']); tep_db_query("update " . TABLE_SESSIONS . " set value = '" . tep_db_input(session_encode()) . "' WHERE sesskey = '" . tep_db_input($sessionID) . "'"); } }
<?php error_reporting(E_ALL); $session_array = explode(";", @session_encode()); print "I live\n";
<?php error_reporting(-1); // Make sure we don't die trying to read an uninitialized session from C++ session_encode(); var_dump($_SESSION); var_dump($GLOBALS['_SESSION']); session_start(); var_dump($_SESSION); var_dump($GLOBALS['_SESSION']);
/** * Extracts session data from storage field set. * @param array $fields storage fields. * @return string session data. */ protected function extractData($fields) { if ($this->readCallback !== null) { if (!isset($fields['data'])) { $fields['data'] = ''; } $extraData = call_user_func($this->readCallback, $fields); if (!empty($extraData)) { session_decode($fields['data']); $_SESSION = array_merge((array) $_SESSION, (array) $extraData); return session_encode(); } return $fields['data']; } else { return isset($fields['data']) ? $fields['data'] : ''; } }
/** * 保存session * @return bool */ public static function sessionWriteClose() { if (PHP_SAPI != 'cli') { return session_write_close(); } if (!empty(HttpCache::$instance->sessionStarted) && !empty($_SESSION)) { $session_str = session_encode(); if ($session_str && HttpCache::$instance->sessionFile) { return file_put_contents(HttpCache::$instance->sessionFile, $session_str); } } return empty($_SESSION); }
<?php error_reporting(E_ALL); class foo { public $bar = "ok"; function method() { $this->yes = "done"; } } $baz = new foo(); $baz->method(); $arr[3] = new foo(); $arr[3]->method(); session_start(); $_SESSION["baz"] = $baz; $_SESSION["arr"] = $arr; print session_encode() . "\n"; session_destroy();
<?php error_reporting(E_ALL); class foo { public $bar = "ok"; function method() { $this->yes = "done"; } } $baz = new foo(); $baz->method(); $arr[3] = new foo(); $arr[3]->method(); session_start(); $_SESSION["baz"] = $baz; $_SESSION["arr"] = $arr; var_dump(session_encode()); session_destroy();
public function testSessionEncode() { $_SESSION['foo'] = 'bar'; $data = unserialize(session_encode()); $this->assertSame('bar', $data['foo']); }