After HTTPS (SSL) is deployed on discuz, ecshop, and 帝国cms, members cannot log in.

Published: 2016-12-26

```html

Note: The following tutorial only applies to the 301 redirect after SSL deployment on our company's Hong Kong/Taiwan virtual hosting or 亚数 cloud hosting Hong Kong IP.

1. discuz cannot log in to the backend after deploying https:


discuz uses $_SERVER[‘HTTPS’] for detection. Our virtual hosting does not support it, and also does not support $_SERVER['HTTP_HOST']; you need to use $_SERVER['HTTP_FROM_HTTPS'] for detection. The same applies to other PHP programs.

source/class/discuz/discuz_application.php (around line 188):

Find:

$_G['isHTTPS'] = ($_SERVER['HTTPS'] && strtolower($_SERVER['HTTPS']) != 'off') ? true : false;

Change to:

$_G['isHTTPS'] = ($_SERVER['HTTP_FROM_HTTPS'] && strtolower($_SERVER['HTTP_FROM_HTTPS']) != 'off') ? true : false;

uc_server/avatar.php (around line 14):

Find:

define('UC_API', strtolower(($_SERVER['HTTPS'] == 'on' ? 'https' : 'http').'://'.$_SERVER['HTTP_HOST'].substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'))));

Change to:

define('UC_API', strtolower(($_SERVER['SERVER_PORT'] == 443 || $_SERVER['HTTP_FROM_HTTPS'] == 'on' ? 'https' : 'http').'://'.$_SERVER['HTTP_HOST'].substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'))));

Note: Using a 301 redirect to force http to jump to https will cause backend uc communication to fail.


2. ecshop cannot log in to the backend after deploying https:


Open includes/cls_ecshop.php around line 154

Find

return (isset($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')) ? 'https://' : 'http://';

Change to:

return isset($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')||(strtolower($_SERVER['HTTP_FROM_HTTPS']) == 'on') ? 'https://' : 'http://';


3. 帝国cms backend login blank after deploying https:


(1) 帝国cms 7.2 and below versions


e/class/connect.php

function eReturnDomain(){
        $domain=RepPostStr($_SERVER['HTTP_HOST'],1);
        if(emptyempty($domain))
        {
                return '';
        }
      // return 'http://'.$domain;    Comment out this line, replace with the following two lines
      $httptype = isset($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')||(strtolower($_SERVER['HTTP_FROM_HTTPS']) == 'on') ? 'https://' : 'http://';
      return $httptype.$domain;
}
function FWeReturnDomain(){
    $domain=RepPostStr($_SERVER['HTTP_HOST'],1);
    if(emptyempty($domain))
    {
        return '';
    }
    //return 'http://'.$domain;  Comment out this line, replace with the following two lines 
      $httptype = isset($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')||(strtolower($_SERVER['HTTP_FROM_HTTPS']) == 'on') ? 'https://' : 'http://'; 
      return $httptype.$domain;
}


(2) 帝国cms 7.5 and above versions


e/config/config.php      'httptype'=>0  # fully automatic

e/class/connect.php

function eCheckUseHttps(){
//if($_SERVER['HTTPS']&&strtolower($_SERVER['HTTPS'])!='off')  Comment out this line, replace with the following line
    if (isset($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')||(strtolower($_SERVER['HTTP_FROM_HTTPS']) == 'on'))
{
return 1;
}
else
{
return 0;
}
}


```