Added is_https() function to common.php #1094

Closed
wants to merge 4 commits into
from

3 participants

@it-can

Added is_https() function to common.php

@narfbg narfbg commented on an outdated diff Feb 29, 2012
system/core/Common.php
@@ -570,5 +570,24 @@ function html_escape($var)
}
}
+// ------------------------------------------------------------------------
+
+/**
+ * Is HTTPS connection?
+ *
+ * Test to see if you are using a HTTPS connection
+ *
+ * @access public
+ * @return bool TRUE if the connection is HTTPS
+ */
+if ( ! function_exists('is_https'))
+{
+ function is_https()
+ {
+ return ( ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') ? TRUE : FALSE;
@narfbg
narfbg added a line comment Feb 29, 2012

Doesn't need to be ternary - the expression itself will return TRUE or FALSE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@narfbg narfbg commented on an outdated diff Feb 29, 2012
system/core/Config.php
@@ -80,7 +80,7 @@ public function __construct()
{
if (isset($_SERVER['HTTP_HOST']))
{
- $base_url = ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http';
+ $base_url = (is_https()) ? 'https' : 'http';
@narfbg
narfbg added a line comment Feb 29, 2012

Just my preferrence, but those brackets are not really needed :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@narfbg narfbg commented on an outdated diff Feb 29, 2012
system/core/Common.php
@@ -570,5 +570,24 @@ function html_escape($var)
}
}
+// ------------------------------------------------------------------------
+
+/**
+ * Is HTTPS connection?
+ *
+ * Test to see if you are using a HTTPS connection
+ *
+ * @access public
@narfbg
narfbg added a line comment Feb 29, 2012

Looks weird compared to the next line, you need to use tabs as separators on both of them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@it-can

Ok @narfbg I changed the code to your comments...

@narfbg

OK, looks good ... only question is - do we really need it? As I already said in the comments for #1087 - it might be too simple to really need a function, so I'll leave this one to some of the other team members to decide.

@skunkbad

Maybe I am wrong, but if you set $base_url to https, how can you make non-https anchors, site_urls, etc? Just my opinion, but just because you are in https doesn't mean that base_url should change. What needs to change is the helpers. There needs to be functions that can make https links, non-https links, and links that are https only if in https. A site needs to be able to go back and forth from http to https and back to http. Setting base_url is wrong.

@it-can

If you set base_url in config.php, it will use that value. If there is no base_url it will automatic create a base_url config value (with https or http). Look at this line: https://github.com/IT-Can/CodeIgniter/blob/90223c8680a21a71cac24a9811f9e38e49296f5d/system/core/Config.php#L30

@skunkbad

Either way, the helpers should be updated. I currently do this by extending the helpers, but cant believe the helpers are not modified to accomodate http and https at the same time. Check out my helper for urls: https://bitbucket.org/skunkbad/community-auth-ci-session-version/src/6ae0d164035d/application/helpers/MY_url_helper.php

@narfbg

3fb0267

@IT-Can It would've taken me some time to explain the changes that needed to be done to your pull request and just commiting it was easier, so I just did that. Nevertheless - thank you for initially submitting this.

@narfbg narfbg closed this Oct 22, 2012
@it-can

@narfbg no problem!

@it-can it-can deleted the unknown repository branch Sep 17, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment