function session_new($length = 86400) { $session_key = session_generate_key(); db_insert('wfpl_sessions', 'session_key,length', $session_key, $length); $GLOBALS['session_id'] = db_auto_id(); $GLOBALS['session_key'] = $session_key; $_REQUEST['session_key'] = $session_key; #just in case someone calls session_exists() after session_new() session_touch($length); return $GLOBALS['session_key']; }
/** * Receives an array of usernames from a remote machine and prods their * sessions to keep them alive * * @param array $array An array of usernames * @return string "All ok" or an error message */ function keepalive_server($array) { global $CFG, $DB; $remoteclient = get_mnet_remote_client(); $CFG->usesid = true; // We don't want to output anything to the client machine $start = ob_start(); // We'll get session records in batches of 30 $superArray = array_chunk($array, 30); $returnString = ''; foreach ($superArray as $subArray) { $subArray = array_values($subArray); $instring = "('" . implode("', '", $subArray) . "')"; $query = "select id, session_id, username from {mnet_session} where username in {$instring}"; $results = $DB->get_records_sql($query); if ($results == false) { // We seem to have a username that breaks our query: // TODO: Handle this error appropriately $returnString .= "We failed to refresh the session for the following usernames: \n" . implode("\n", $subArray) . "\n\n"; } else { foreach ($results as $emigrant) { session_touch($emigrant->session_id); } } } $end = ob_end_clean(); if (empty($returnString)) { return array('code' => 0, 'message' => 'All ok', 'last log id' => $remoteclient->last_log_id); } return array('code' => 1, 'message' => $returnString, 'last log id' => $remoteclient->last_log_id); }
function session_start_php3() { // $debug=1; global $php3SessionID, $auctionref; if ($debug) { printf("Recieved session=%s<br>", $php3SessionID); } if (!session_valid_session($php3SessionID)) { $php3SessionID = session_begin_session($auctionref); } else { session_loadvars($php3SessionID); } session_touch($php3SessionID); }