Example #1
0
 /**
  * Requires SSL by redirecting non-SSL requests to the corresponding SSL endpoint
  * i.e. http://foo.com/test REDIRECTS TO https://food.com/test
  * 
  * @throws _Exception If $_SERVER variables are not set
  */
 public static function _requireSSL()
 {
     if (!self::_isSSL()) {
         if (isset($_SERVER) && isset($_SERVER['HTTP_HOST']) && isset($_SERVER['REQUEST_URI'])) {
             header("HTTP/1.1 301 Moved Permanently");
             header("Location: https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
             exit;
         } else {
             _Log::fatal('$_SERVER variables are not set.  Unable to require SSL');
             throw new _Exception('$_SERVER variables are not set.  Unable to require SSL');
         }
     }
 }
 /**
  * Sends the HTTP status code
  * 
  * 
  * @param int $code The code to send
  * @param type $customDescription (optional) The description of the response code
  */
 public static function _sendHTTPStatusCode($code, $customDescription = FALSE)
 {
     if (!preg_match('/\\d\\d\\d/', $code)) {
         _Log::warn("Invalid status code: {$code} - Using default '200 OK' response");
         $code = 200;
     }
     if ($customDescription === FALSE) {
         $description = isset(_WebResponseIncludes::$STATUS_CODES[$code]) ? _WebResponseIncludes::$STATUS_CODES[$code] : '';
     } else {
         $description = $customDescription;
     }
     header("HTTP/1.0 {$code} {$description}");
 }
function log_message($level = 2, $message, $php_error = FALSE)
{
    global $config;
    if ($config['log_errors'] === FALSE) {
        return;
    }
    if (!class_exists('_Log')) {
        include_once BASEPATH . 'libraries/Log.php';
    }
    if (!isset($LOG)) {
        $LOG = new _Log($config['log_path'], $config['log_threshold'], $config['log_date_format']);
    }
    $LOG->write_log($level, $message, $php_error);
}
Example #4
0
 /**
  * Creates the connection to the MySQL DB through the MySQLi interface
  * 
  * @param boolean $useExceptions (optional) | Override on whether to use exceptions.  If not passed will use _DB_USE_EXCEPTIONS
  * @return boolean | TRUE on success (connection was made) / FALSE on failure
  * @throws _Exception | If _DB_USE_EXCEPTIONS is TRUE, will throw an exception instead of returning
  * false on connection error
  */
 private function createConnection($useExceptions = _DbConfig::USE_EXCEPTIONS)
 {
     $this->mysqli = new \mysqli($this->host, $this->username, $this->password, $this->dbName, $this->port, $this->socket);
     if (mysqli_connect_errno()) {
         $msg = 'Unable to connect to MySQL | ' . mysqli_connect_error();
         if ($useExceptions) {
             _Log::fatal($msg);
             $_e = new _Exception($msg, 0, $e);
             throw $_e;
         } else {
             _Log::warn($msg);
         }
     }
     if (isset($this->mysqli) && $this->mysqli !== NULL) {
         // set charset
         $rc = $this->mysqli->set_charset(_DbConfig::CHARSET);
         if ($rc !== TRUE) {
             _Log::warn('Error setting character set');
         }
         $this->isConnected = true;
         return TRUE;
     }
     return FALSE;
 }
Example #5
0
 /**
  * 
  * @param string $filename The file to open
  * @param const $permissions The permissions
  * @return boolean TRUE if file was opened / FALSE if file was unable to be opened
  */
 private function openFile($filename, $permissions = _FileConstants::READ_WRITE_END_OF_FILE_CREATE)
 {
     $this->closeFile();
     if ($filename === NULL) {
         _Log::debug('Invalid filename specified');
         return false;
     }
     if ($filename == _FileConstants::TMP) {
         $this->filename = tempnam($this->getTemporaryFileDirectory(), '_');
         $this->fh = tmpfile();
     } else {
         $this->filename = $filename;
         $this->fh = fopen($filename, $permissions);
     }
     if ($this->fh !== FALSE) {
         $this->filePermissions = $permissions;
         return TRUE;
     }
     return FALSE;
 }