欢迎来到 54818模板网!这是一个yzmcms的模板分享站。

从PHP5升级到PHP7导致QQ不能登录网站的问题

相关案例演示

        由于一些小原因昨天我把网站的PHP版本从5.3升级到7.2。当时没有发现什么问题。升级更高版本功能肯定更好。但相应的可能也会出现一些小问题对新版本不兼容。

        为了安全考虑,我管理网站一直是用的QQ登录网站后台,不输入密码,扫一扫就登录后台,非常好用,非常安全。今天我发现QQ登录网站后台出现了错误,不能登录,前台会员登录也出现相同的错误,同样不能登录。唉~可以理解,新版本老是会出现这样那样的问题。错误日志如下:

<?php exit;?> Error : 2021-08-31 09:24:18 | 2 | file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed | /data/home/htdocs/yzmphp/core/class/qqapi.class.php | 44

<?php exit;?> Error : 2021-08-31 09:24:18 | 2 | file_get_contents(): Failed to enable crypto | /data/home/htdocs/yzmphp/core/class/qqapi.class.php | 44

<?php exit;?> Error : 2021-08-31 09:24:18 | 2 | file_get_contents(https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&amp;client_id=XXX&amp;client_secret=XXXX&amp;code=XXXX&amp;redirect_uri=https%3A%2F%2Fwww.54818.cn%2Fmember%2Fother%2Fqq_login.html): failed to open stream: operation failed | /data/home/htdocs/yzmphp/core/class/qqapi.class.php | 44

        查看错误日志,我们就可以排除了并非QQ登录后台插件的问题。而是网站系统qqapi.class.php文件里 file_get_contents() 和 SSL相关的问题。看样子是域名采用HTTPS访问,网站开启了SSL,就会有这样的错误。


        根据错误日志,我们找到 /yzmphp/core/class/qqapi.class.php 文件的第44行。代码如下 

$content = file_get_contents( $url);


        之前PHP5版本QQ登录正常。现在PHP7出现问题,安全要求更高。通过百度问题,我发现有几种方法。网站用的是虚机,访问的QQ网址又是非常安全的,综合考虑下,还是用最直接的方法来解决问题。

//定义一个变量
$ymssl=array("ssl"=>array( "verify_peer"=>false, "verify_peer_name"=>false,), );

//把文件里的三处调用函数修改成
$content = file_get_contents( $url, false, stream_context_create($ymssl));

        完美解决。登录正常了。

    作者:54818模板网 关注:1288 时间:2021-08-31 11:18:40
    相关网站教程