How to get current protocol of current site?

    $isSecure = false;
    if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
        $isSecure = true;
    }elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVE['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
        $isSecure = true;
    }
    $protocol = $isSecure ? 'https://' : 'http://';
    echo $protocol;

    /*** Mostly its used setting base url. Like codeigniter's config file for base url
        For Ex.: $config['base_url']= $protocol.$_SERVER['HTTP_HOST'].'/site_directory/';

    ***/

Comments

Popular posts from this blog