Issues (27)

example/demo/connect.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * Oauth2登录SDK
4
 **/
5
session_start();
6
@header('Content-Type: text/html; charset=UTF-8');
0 ignored issues
show
Are you sure the usage of header('Content-Type: text/html; charset=UTF-8') is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
7
8
// 引用vendor
9
require __DIR__.'/../../vendor/autoload.php';
10
require __DIR__.'/../oauth2.php';
11
12
// 配置文件
13
$oauthConfig = require '../config/params.php';
14
15
$type = isset($_GET['type']) ? $_GET['type'] : 'qq';
16
$oauth = new oauth2($oauthConfig);
17
18
if (!empty($_GET['code'])) {
19
    try {
20
        $arr = $oauth->callback($type);
21
        if (isset($arr['code']) && $arr['code'] == 0) {
22
            /* 处理用户登录逻辑 */
23
            $_SESSION['user'] = $arr['userInfo'];
24
            exit("<script language='javascript'>window.location.href='./';</script>");
25
26
        } elseif (isset($arr['code'])) {
27
            exit('登录失败,返回错误原因:' . $arr['msg']);
28
        } else {
29
            exit('获取登录数据失败');
30
        }
31
    }catch (\Exception $exception){
32
        echo $exception->getFile();
33
        echo $exception->getLine();
34
        echo $exception->getMessage();
35
        exit();
36
    }
37
} else {
38
    $arr = $oauth->login($type);
39
     if (isset($arr['code']) && $arr['code'] == 0) {
40
         exit("<script language='javascript'>window.location.href='{$arr['url']}';</script>");
41
     } elseif (isset($arr['code'])) {
42
         exit('登录接口返回:' . $arr['msg']);
43
     } else {
44
         exit('获取登录地址失败');
45
     }
46
}
47