cvs: bugtracker /includes session.php /template/generic/user logout.php

From: Date: Wed, 13 Aug 2008 10:23:28 +0000
Subject: cvs: bugtracker /includes session.php /template/generic/user logout.php
Groups: php.webmaster 
Request: Send a blank email to php-webmaster+get-2386@lists.php.net to get a copy of this message
bcarlyon Wed Aug 13 10:23:28 2008 UTC Added files: /bugtracker/includes session.php /bugtracker/template/generic/user logout.php Log: Forgot to cvs add yesterdays session.php and todays logout.php http://cvs.php.net/viewvc.cgi/bugtracker/includes/session.php?view=markup&rev=1.1 Index: bugtracker/includes/session.php +++ bugtracker/includes/session.php <?php /* Copyright (c) 2008, Barry Carlyon <bcarlyon@php.net> All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the GSOC_PHP_BUGTRACKER nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ class session { public $session_id = ''; public $ip_address = ''; public $handle = ''; public $last_page = ''; public $current_page = ''; function initialize() { trace('session initialize'); global $db, $template, $user; $this->current_page = $template->page; //first job tidy up old sessions, lets go for 15mins $later = time() - (15 * 60); $query = 'DELETE FROM ' . SESSION_TABLE . ' WHERE UNIX_TIMESTAMP(last_active) < \'' . $later . '\''; $db->get_data($query); trace($db->affected_rows . ' Killed Sessions'); $this->ip_address = $_SERVER['REMOTE_ADDR']; if (isset($this->cookie_session_id)) { $query = 'SELECT * FROM ' . SESSION_TABLE . ' WHERE session_id = \'' . $this->cookie_session_id . '\''; $db->get_data($query); if ($db->total_rows == 1) { //then the session id matches $this->session_id = $this->cookie_session_id; //check ip $row = $db->fetch_row(); if ($row['ip_address'] == $this->ip_address) { trace('Session is valid, going for session update'); //then the session id is valid for this ip as well //update the cookie $this->update_session($row); } else { //spooofed! $user->logged_in = FALSE; $this->end_session(); } } else { $user->logged_in = FALSE; } } return; } function create_session() { trace('session create'); global $user, $db; $session_id = md5( md5($user->handle) . md5(time()) ); $this->session_id = $session_id; $query = 'INSERT INTO ' . SESSION_TABLE . '(session_id,handle,ip_address,last_page) VALUES (\'' . $session_id . '\',\'' . $user->handle . '\',\'' . $this->ip_address . '\',\'login\')'; $db->get_data($query); if ($db->affected_rows && $user->write_cookie('', 'session=' . $this->session_id)) { return TRUE; } return; } function update_session($session_data) { trace('session update'); global $user, $db; $user->handle = $session_data['handle']; $user->logged_in = TRUE; $query = 'UPDATE ' . SESSION_TABLE . ' SET last_page = \'' .$this->current_page . '\', last_active = NOW() WHERE session_id = \'' . $this->session_id . '\''; $db->get_data($query); if ( (!$user->write_cookie('', 'session=' . $this->session_id)) || (!$db->affected_rows) ) { $user->write_cookie('', '', 0); trigger_error('Session Update Failed, you have been logged out',E_USER_ERROR); } return TRUE; } function end_session() { trace('session end'); global $user, $db, $template; $query = 'DELETE FROM ' . SESSION_TABLE . ' WHERE session_id = \'' . $this->session_id . '\''; $db->get_data($query); $user->write_cookie('', '', 0); $this->session_id = ''; $template->meta_refresh('/'); $user->logged_in = FALSE; trigger_error('You have been Logged Out Successfully', E_USER_ERROR); } } http://cvs.php.net/viewvc.cgi/bugtracker/template/generic/user/logout.php?view=markup&rev=1.1 Index: bugtracker/template/generic/user/logout.php +++ bugtracker/template/generic/user/logout.php <?php /* Copyright (c) 2008, Barry Carlyon <bcarlyon@php.net> All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the GSOC_PHP_BUGTRACKER nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ //so user wants to logout do they? $session->end_session();

« previous php.webmaster (#2386) next »