PHPCMS开发

当前位置/ 首页/ V9教程/PHPCMS开发/ 正文

phpcmsv9全站 https ssl后会员登录失败解决方法

很多朋友在使用phpcmsv9的时候遇到了这样一个问题,在将全站https化后,会员中心无法正常登录,具体是没有返回值,提示登录失败,主要是原来是系统在初始化phpsso时,无法将数据通过443传输到对应的方法,通过排查问题,可以看到在client.class.php中,系统默认使用的端口是80,所以我们只需要按以下方法修改就可以解决在https后会员无法登录的问题:

phpcms/modules/member/classes/client.class.php 
 
中361行修改如下:
$port = !empty($matches['port']) ? $matches['port'] : ( strtolower($matches['scheme'])=='https' ? 443 : 80 );
第386行将:
$fp = @fsockopen(($ip ? $ip : $host), $port, $errno, $errstr, $timeout);
替换为
$contextOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false
    )
);
//如果有签名的证书
//$contextOptions = array(
//    'ssl' => array(
//        'verify_peer' => true, 
//        'cafile' => '/path/to/cacert.pem',
//        //'CN_match' => 'indexroot.net', // 匹配域名
//        'ciphers' => 'HIGH:!SSLv2:!SSLv3',
//        'disable_compression' => true,
//    )
//);
$context = stream_context_create($contextOptions);
$fp = stream_socket_client("ssl://{$host}:{$port}", $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $context);
 
后台更新缓存,会员登录就成功了!