CodeIgniter Forums
Need is_https() - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forum-29.html)
+--- Thread: Need is_https() (/thread-77459.html)



Need is_https() - murad_ali - 09-03-2020

Hi 
Can you please add isHttps as your system common function.
Code:
if ( ! function_exists('isHttps'))
{
    /**
     * Is HTTPS?
     *
     * Determines if the application is accessed via an encrypted
     * (HTTPS) connection.
     *
     * @return    bool
     */
    function isHttps()
    {
        if ( ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off')
        {
            return TRUE;
        }
        elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) === 'https')
        {
            return TRUE;
        }
        elseif ( ! empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off')
        {
            return TRUE;
        }

        return FALSE;
    }
}



RE: Need is_https() - MGatner - 09-10-2020

This is already part of the IncomingRequest class, isSecure(). You can access it anywhere like so:

service(‘request’)->isSecure()

https://github.com/codeigniter4/CodeIgniter4/blob/f9613ad1411ec01f14140eb3e75c969b1446a3f4/system/HTTP/IncomingRequest.php#L292


RE: Need is_https() - murad_ali - 09-10-2020

Thanks dear, I just got it.