Skip to content
Browse files

Merge remote-tracking branch 'dstockto/cs_ssl'

  • Loading branch information...
2 parents b1a1364 + fcfc3eb commit ad1acd0e656ec9128a6209dab8ca6e37e1d44c51 @lornajane lornajane committed
Showing with 73 additions and 26 deletions.
  1. +73 −26 src/system/application/libraries/SSL.php
View
99 src/system/application/libraries/SSL.php
@@ -1,61 +1,108 @@
<?php
+/**
+ * SSL Class
+ *
+ * PHP version 5
+ *
+ * @category Joind.in
+ * @package Configuration
+ * @copyright 2009 - 2012 Joind.in
+ * @license http://github.com/joindin/joind.in/blob/master/doc/LICENSE JoindIn
+ */
+
+/**
+ * SSL Class
+ *
+ * PHP version 5
+ *
+ * @category Joind.in
+ * @package Configuration
+ * @copyright 2009 - 2012 Joind.in
+ * @license http://github.com/joindin/joind.in/blob/master/doc/LICENSE JoindIn
+ */
+class SSL
+{
-class SSL {
-
/**
* Array listing of secure URLs
*/
- private $_secure_url = array(
+ private $_secure_url = array(
"/user/login"
);
/**
* CodeIgniter instance
*/
- private $ci = null;
-
- public function __construct() {
- $this->ci=&get_instance();
+ protected $ci = null;
+
+ /**
+ * Instantiate the class and get codeigniter instance
+ */
+ public function __construct()
+ {
+ $this->ci = &get_instance();
}
-
+
/**
* Main routing function
+ *
* @param string $path User-defined path
+ *
+ * @return void
*/
- public function sslRoute($path='') {
+ public function sslRoute($path = '')
+ {
// Check to see if the "USE_SSL" is in config
- $use_ssl=$this->ci->config->item('use_ssl');
- if (!$use_ssl) return;
-
- if (empty($path)) { $path=$_SERVER['REQUEST_URI']; }
+ $use_ssl = $this->ci->config->item('use_ssl');
+ if (!$use_ssl) {
+ return;
+ }
+
+ if (empty($path)) {
+ $path = $_SERVER['REQUEST_URI'];
+ }
if ($this->isSecure($path) && !$this->isRequestSecure()) {
- header('Location: '.$this->buildRedirect($path));
+ header('Location: ' . $this->buildRedirect($path));
}
}
-
+
/**
* Check to see if the given path is secure
+ *
* @param string $path User-defined path
+ *
+ * @return boolean
*/
- private function isSecure($path) {
+ private function isSecure($path)
+ {
return (in_array($path, $this->_secure_url)) ? true : false;
}
-
+
/**
* Check to see if the current request is on HTTPS
+ *
+ * @return boolean
*/
- private function isRequestSecure() {
- return (isset($_SERVER['SECURE']) && $_SERVER['SECURE']==1) ? true : false;
+ private function isRequestSecure()
+ {
+ return (isset($_SERVER['SECURE']) && $_SERVER['SECURE'] == 1) ? true : false;
}
-
+
/**
* Make our redirect link to the other side...
- * @param string $path
+ *
+ * @param string $path Path to redirect or request uri if empty
+ *
+ * @return string
*/
- private function buildRedirect($path='') {
- if (empty($path)) { $path=$_SERVER['REQUEST_URI']; }
- $base_url=$this->ci->config->item('base_url');
- return str_replace('http','https', $base_url).$path;
+ private function buildRedirect($path = '')
+ {
+ if (empty($path)) {
+ $path = $_SERVER['REQUEST_URI'];
+ }
+ $base_url = $this->ci->config->item('base_url');
+
+ return str_replace('http', 'https', $base_url) . $path;
}
-
+
}

0 comments on commit ad1acd0

Please sign in to comment.
Something went wrong with that request. Please try again.