Beispiel #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');
         }
     }
 }
Beispiel #2
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;
 }