class_session.php

来自「sabreipb 2.1.6 utf-8中文版本!」· PHP 代码 · 共 1,207 行 · 第 1/3 页

PHP
1,207 行
字号
													  ),												"id='{$this->session_id}'"											  );    }                             /*-------------------------------------------------------------------------*/    // Get a session based on the current session ID    /*-------------------------------------------------------------------------*/        function get_session($session_id="")    {		//-----------------------------------------		// INIT    	//-----------------------------------------    	        $result     = array();        $query      = "";        $session_id = preg_replace("/([^a-zA-Z0-9])/", "", $session_id);                if ( $session_id )        {			if ( $this->ipsclass->vars['match_browser'] == 1 )			{				$query = " AND browser='".$this->ipsclass->user_agent."'";			}						if ( $this->ipsclass->vars['match_ipaddress'] == 1 )			{				$query .= " AND ip_address='".$this->ipsclass->ip_address."'";			}						$this->ipsclass->DB->simple_construct( array( 'select' => 'id, member_id, running_time, location',														  'from'   => 'sessions',														  'where'  => "id='".$session_id."'".$query												 )      );							$this->ipsclass->DB->simple_exec();						if ( $this->ipsclass->DB->get_num_rows() != 1 )			{				//-----------------------------------------				// Either there is no session, or we have more than one session..				//-----------------------------------------								$this->session_dead_id   = $session_id;				$this->session_id        = 0;        		$this->session_user_id   = 0;        		return;			}			else			{				$result = $this->ipsclass->DB->fetch_row();								if ($result['id'] == "")				{					$this->session_dead_id   = $session_id;					$this->session_id        = 0;					$this->session_user_id   = 0;					unset($result);					return;				}				else				{					$this->session_id        = $result['id'];					$this->session_user_id   = $result['member_id'];					$this->last_click        = $result['running_time'];        			$this->location          = $result['location'];        			unset($result);					return;				}			}		}    }        /*-------------------------------------------------------------------------*/    //    // Creates a member session.    //    /*-------------------------------------------------------------------------*/        function create_member_session()    {        if ($this->member['id'])        {        	//-----------------------------------------        	// Remove the defunct sessions        	//-----------------------------------------        				$this->ipsclass->vars['session_expiration'] = $this->ipsclass->vars['session_expiration'] ? (time() - $this->ipsclass->vars['session_expiration']) : (time() - 3600);						$this->ipsclass->DB->simple_construct( array( 'delete' => 'sessions', 'where' => "member_id=".$this->member['id'] ) );			$this->ipsclass->DB->simple_exec();						$this->session_id  = md5( uniqid(microtime()) );						//-----------------------------------------			// Get module settings			//-----------------------------------------						$vars = $this->_get_location_settings();        	        	//-----------------------------------------			// Still update?			//-----------------------------------------			 			if ( ! $this->do_update )			{				return;			}        			//-----------------------------------------        	// Insert the new session        	//-----------------------------------------        	        	$this->ipsclass->DB->do_shutdown_insert( 'sessions',													 array(															'id'                 => $this->session_id,															'member_name'        => $this->member['members_display_name'],															'member_id'          => intval($this->member['id']),															'member_group'       => $this->member['mgroup'],															'login_type'         => substr($this->member['login_anonymous'],0, 1),															'running_time'       => $this->time_now,															'ip_address'         => $this->ipsclass->ip_address,															'browser'            => $this->ipsclass->user_agent,															'location'           => $vars['location'],															'in_error'           => 0,															'location_1_type'    => $vars['1_type'],															'location_1_id'      => $vars['1_id'],															'location_2_type'    => $vars['2_type'],															'location_2_id'      => $vars['2_id'],															'location_3_type'    => $vars['3_type'],															'location_3_id'      => $vars['3_id'],														  )												  );						//-----------------------------------------			// If this is a member, update their last visit times, etc.			//-----------------------------------------						if ( time() - $this->member['last_activity'] > 3600 )			{				//-----------------------------------------				// Reset the topics read cookie..				//-----------------------------------------								$this->ipsclass->my_setcookie('topicsread', '');								list( $be_anon, $loggedin ) = explode( '&', $this->member['login_anonymous'] );								$this->ipsclass->DB->simple_construct( array( 'update' => 'members',															  'set'    => "login_anonymous='$be_anon&1', last_visit=last_activity, last_activity=".$this->time_now,															  'where'  => "id=".$this->member['id']													 )      );									$this->ipsclass->DB->simple_shutdown_exec();								//-----------------------------------------				// Fix up the last visit/activity times.				//-----------------------------------------								$this->ipsclass->input['last_visit']    = $this->member['last_activity'];				$this->ipsclass->input['last_activity'] = $this->time_now;			}		}		else		{			$this->create_guest_session();		}    }        /*-------------------------------------------------------------------------*/    //    // Create guest session    //    /*-------------------------------------------------------------------------*/        function create_guest_session()    {		//-----------------------------------------    	// INIT    	//-----------------------------------------    	    	$query = array();    	    	$this->ipsclass->vars['session_expiration'] = $this->ipsclass->vars['session_expiration'] ? (time() - $this->ipsclass->vars['session_expiration']) : (time() - 3600);				//-----------------------------------------		// Remove the defunct sessions		//-----------------------------------------				if ( ($this->session_dead_id != 0) and ( ! empty($this->session_dead_id) ) )		{			$query[] = "id='".$this->session_dead_id."'";		}		else if ( $this->ipsclass->vars['match_ipaddress'] == 1 )		{			$query[] = "ip_address='".$this->ipsclass->ip_address."'";		}				if ( count( $query ) )		{			$this->ipsclass->DB->simple_construct( array( 'delete' => 'sessions', 'where'  => implode( " OR ", $query ) ) );			$this->ipsclass->DB->simple_exec();		}								 		$this->session_id  = md5( uniqid(microtime()) );				//-----------------------------------------        // Get module settings        //-----------------------------------------                $vars = $this->_get_location_settings();                //-----------------------------------------        // Still update?        //-----------------------------------------                 if ( ! $this->do_update )        {        	return;        }        		//-----------------------------------------		// Insert the new session		//-----------------------------------------				$this->ipsclass->DB->do_shutdown_insert( 'sessions',												 array(														'id'                 => $this->session_id,														'member_name'        => '',														'member_id'          => 0,														'member_group'       => $this->ipsclass->vars['guest_group'],														'login_type'         => 0,														'running_time'       => $this->time_now,														'ip_address'         => $this->ipsclass->ip_address,														'browser'            => $this->ipsclass->user_agent,														'location'           => $vars['location'],														'in_error'           => 0,														'location_1_type'    => $vars['1_type'],														'location_1_id'      => $vars['1_id'],														'location_2_type'    => $vars['2_type'],														'location_2_id'      => $vars['2_id'],														'location_3_type'    => $vars['3_type'],														'location_3_id'      => $vars['3_id'],													  )											  );    }        /*-------------------------------------------------------------------------*/    // Creates a BOT session    /*-------------------------------------------------------------------------*/        function create_bot_session($bot, $name="")    {    	//-----------------------------------------        // Get module settings        //-----------------------------------------                $vars = $this->_get_location_settings();                $this->ipsclass->DB->do_shutdown_insert( 'sessions',												 array(														'id'                 => $bot.'='.str_replace('.','',$this->ipsclass->ip_address ).'_session',														'member_name'        => $name ? $name : $bot,														'member_id'          => 0,														'member_group'       => $this->ipsclass->vars['spider_group'],														'login_type'         => $this->ipsclass->vars['spider_anon'],														'running_time'       => $this->time_now,														'ip_address'         => $this->ipsclass->ip_address,														'browser'            => $this->ipsclass->user_agent,														'location'           => $vars['location'],														'in_error'           => 0,														'location_1_type'    => $vars['1_type'],														'location_1_id'      => $vars['1_id'],														'location_2_type'    => $vars['2_type'],														'location_2_id'      => $vars['2_id'],														'location_3_type'    => $vars['3_type'],														'location_3_id'      => $vars['3_id'],													  )											  );    }        /*-------------------------------------------------------------------------*/    // Updates a BOT current session.    /*-------------------------------------------------------------------------*/        function update_bot_session($bot, $name="")    {    	//-----------------------------------------        // Get module settings        //-----------------------------------------                $vars = $this->_get_location_settings();        		$this->ipsclass->DB->do_shutdown_update( 'sessions',												 array(														'member_name'        => $name ? $name : $bot,														'member_id'          => 0,														'member_group'       => $this->ipsclass->vars['spider_group'],														'login_type'         => $this->ipsclass->vars['spider_anon'],														'running_time'       => $this->time_now,														'location'           => $vars['location'],														'in_error'           => 0,														'location_1_type'    => $vars['1_type'],														'location_1_id'      => $vars['1_id'],														'location_2_type'    => $vars['2_type'],														'location_2_id'      => $vars['2_id'],														'location_3_type'    => $vars['3_type'],														'location_3_id'      => $vars['3_id'],													  ),												  "id='".$bot.'='.str_replace('.','',$this->ipsclass->ip_address )."_session'"											  );    }        /*-------------------------------------------------------------------------*/    // Returns a "clean" query string    /*-------------------------------------------------------------------------*/        function _get_location_settings()    {    	//-----------------------------------------    	// INIT    	//-----------------------------------------    	    	$return = array();    	$module = $this->ipsclass->input['automodule'] ? $this->ipsclass->input['automodule'] : $this->ipsclass->input['module'];    	    	//-----------------------------------------    	// MODULE?    	//-----------------------------------------    	    	if ( $module )    	{    		$filename = ROOT_PATH.'sources/components_location/'.$this->ipsclass->txt_alphanumerical_clean( $module ).'.php';							if ( file_exists( $filename ) )			{				require_once( $filename );				$toload           = 'components_location_'.$module;				$loader           = new $toload;				$loader->ipsclass =& $this->ipsclass;								$return = $loader->get_session_variables();				$return['location'] = 'mod:'.$module;			}    	}    	    	//-----------------------------------------    	// FORUM    	//-----------------------------------------    	    	else if ( $this->ipsclass->input['act'] == 'sf' AND $this->ipsclass->input['f'] )    	{    		$return = array( 'location' => 'sf',    						 '2_type'   => 'forum',    						 '2_id'     => intval($this->ipsclass->input['f']) );    	}    	    	//-----------------------------------------    	// TOPIC    	//-----------------------------------------    	    	else if ( $this->ipsclass->input['act'] == 'st' AND $this->ipsclass->input['t'] )    	{    		$return = array( 'location' => 'st',    						 '1_type'   => 'topic',    						 '1_id'     => intval($this->ipsclass->input['t']),    						 '2_type'   => 'forum',    						 '2_id'     => intval($this->ipsclass->input['f']) );    	}    	    	//-----------------------------------------    	// POST    	//-----------------------------------------    	    	else if ( $this->ipsclass->input['act'] == 'post' AND $this->ipsclass->input['f'] )    	{    		$return = array( 'location' => 'post',    			 			 '1_type'   => 'topic',    						 '1_id'     => intval($this->ipsclass->input['t']),    						 '2_type'   => 'forum',    						 '2_id'     => intval($this->ipsclass->input['f']) );    	}    	    	//-----------------------------------------    	// OTHER    	//-----------------------------------------    	    	else    	{    		$return = array( 'location' => $this->ipsclass->input['act'].",".$this->ipsclass->input['p'].",".$this->ipsclass->input['CODE'] );    	}    	    	return $return;    }            }?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?