Пример #1
0
 /**
  * Fetch the encryption key
  *
  * Returns it as MD5 in order to have an exact-length 128 bit key.
  * Mcrypt is sensitive to keys that are not the correct length
  *
  * @access	public
  * @param	string
  * @return	string
  */
 public function get_key($key = '')
 {
     if ($key == '') {
         if ($this->encryption_key != '') {
             return $this->encryption_key;
         }
         $key = config_item('encryption_key');
         if ($key == FALSE) {
             show_error(ld_msg('enc_lib_msg_001'));
         }
     }
     return md5($key);
 }
Пример #2
0
 /**
  * Session Constructor
  *
  * The constructor runs the session routines automatically
  * whenever the class is instantiated.
  */
 function __construct()
 {
     // Set all the session preferences, which can either be set
     // manually via the $params array above or via the config file
     foreach (array('sess_encrypt_cookie', 'sess_expiration', 'sess_expire_on_close', 'sess_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path', 'cookie_domain', 'cookie_secure', 'sess_time_to_update', 'time_reference', 'cookie_prefix', 'encryption_key') as $key) {
         $this->{$key} = isset($params[$key]) ? $params[$key] : config_item($key);
     }
     if ($this->encryption_key == '') {
         show_error(ld_msg('session_msg_001'));
     }
     // Do we need encryption? If so, load the encryption class
     if ($this->sess_encrypt_cookie == TRUE) {
         $this->ENC =& load_class('Encryption');
     }
     // Set the "now" time.  Can either be GMT or server time, based on the
     // config prefs.  We use this to set the "last activity" time
     $this->now = get_time();
     // Set the session length. If the session expiration is
     // set to zero we'll set the expiration two years from now.
     if ($this->sess_expiration == 0) {
         $this->sess_expiration = 60 * 60 * 24 * 365 * 2;
     }
     // Set the cookie name
     $this->sess_cookie_name = $this->cookie_prefix . $this->sess_cookie_name;
     // Run the Session routine. If a session doesn't exist we'll
     // create a new one.  If it does, we'll update it.
     if (!$this->sess_read()) {
         $this->sess_create();
     } else {
         $this->sess_update();
     }
     // Delete 'old' flashdata (from last request)
     $this->_flashdata_sweep();
     // Mark all new flashdata as old (data will be deleted before next request)
     $this->_flashdata_mark();
     // Delete expired sessions if necessary
     $this->_sess_gc();
 }
Пример #3
0
 /**
  * Display an error message
  *
  * @access	private
  * @param	string	the error message
  * @return	string	sends the application/error_db.php template
  */
 private function display_error($error = '')
 {
     // check whether display error or not !!!
     if ($this->db_debug === FALSE) {
         return;
     }
     $heading = ld_msg('display_err_002');
     $message = $error;
     // Find the most likely culprit of the error by going through
     // the backtrace until the source file is no longer in the
     // database folder.
     $trace = debug_backtrace();
     foreach ($trace as $call) {
         if (isset($call['file']) and strpos($call['file'], SITE_ROOT) === FALSE) {
             // Found it - use a relative path for safety
             $message[] = 'Filename: ' . str_replace(SITE_ROOT, '', $call['file']);
             $message[] = 'Line Number: ' . $call['line'];
             break;
         }
     }
     echo show_error($message, $heading, 'error_db');
     exit;
 }
Пример #4
0
 function set_status_header($code = 200, $text = '')
 {
     $stati = array(200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 304 => 'Not Modified', 305 => 'Use Proxy', 307 => 'Temporary Redirect', 400 => 'Bad Request', 401 => 'Unauthorized', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Timeout', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Long', 415 => 'Unsupported Media Type', 416 => 'Requested Range Not Satisfiable', 417 => 'Expectation Failed', 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Timeout', 505 => 'HTTP Version Not Supported');
     if ($code == '' or !is_numeric($code)) {
         show_error(ld_msg('header_sts_code_001'));
     }
     if (isset($stati[$code]) and $text == '') {
         $text = $stati[$code];
     }
     if ($text == '') {
         show_error(ld_msg('header_sts_code_002'));
     }
     $server_protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : FALSE;
     if (substr(php_sapi_name(), 0, 3) == 'cgi') {
         header("Status: {$code} {$text}", TRUE);
     } elseif ($server_protocol == 'HTTP/1.1' or $server_protocol == 'HTTP/1.0') {
         header($server_protocol . " {$code} {$text}", TRUE, $code);
     } else {
         header("HTTP/1.1 {$code} {$text}", TRUE, $code);
     }
 }
Пример #5
0
 function base_url()
 {
     $base_url = config_item('base_url');
     if ($base_url !== FALSE and $base_url != '') {
         return $base_url = rtrim($base_url . '/', '/') . '/';
     } else {
         show_error(ld_msg('err_001'));
     }
 }