Skip to content

Commit

Permalink
1. 完善优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
shinn-lancelot committed Aug 23, 2018
1 parent f387642 commit e51e125
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion admin.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

session_start();
$user = $_SESSION['wop_admin_user'];
$user = isset($_SESSION['wop_admin_user']) ? $_SESSION['wop_admin_user'] : '';
empty($user) && header('Location: ./login.php');

?>
Expand Down
4 changes: 2 additions & 2 deletions common/logoutHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
$res['message'] = '退出失败!';

session_start();
$token = $_SESSION['wop_admin_user'];
if (!$token) {
$user = isset($_SESSION['wop_admin_user']) ? $_SESSION['wop_admin_user'] : '';
if (!$user) {
echo json_encode($res);
exit();
}
Expand Down
6 changes: 3 additions & 3 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

// 有code且代理作用域为code,拼接code和state参数,直接跳转回请求源
if (!empty($code) && $proxyScope == 'code') {
$redirectUri = $_COOKIE['redirect_uri'];
$redirectUri = isset($_COOKIE['redirect_uri']) ? $_COOKIE['redirect_uri'] : '';
if (!empty($redirectUri)) {
$mark = strpos($redirectUri, '?') === false ? '?' : '';
header('Location:' . $redirectUri . $mark . '&code=' . $code . '&state=' . $state);
Expand Down Expand Up @@ -50,7 +50,7 @@
} else if ($proxyScope == 'access_token') {
$cacheDir = __DIR__ . '/Cache/appid_' . $appId;
session_start();
$openid = $_SESSION['openid_' . $appId];
$openid = isset($_SESSION['openid_' . $appId]) ? $_SESSION['openid_' . $appId] : '';
$res = json_decode(file_get_contents($cacheDir . '/access_token_openid_' . $openid . '.json'), true);
// access_token缓存文件不存在或者access_token已过期或者openid已过期,则重新获取
if (!$res || $res['expire_time'] <= time() || empty($openid)) {
Expand Down Expand Up @@ -104,7 +104,7 @@
}

if (!isset($res['errcode']) || empty($res['errcode'])) {
$redirectUri = $_COOKIE['redirect_uri'];
$redirectUri = isset($_COOKIE['redirect_uri']) ? $_COOKIE['redirect_uri'] : '';
if (!empty($redirectUri)) {
$mark = strpos($redirectUri, '?') === false ? '?' : '';
header('Location:' . $redirectUri . $mark . '&access_token=' . $res['access_token'] . '&openid=' . $openid);
Expand Down
2 changes: 1 addition & 1 deletion login.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

session_start();
$user = $_SESSION['wop_admin_user'];
$user = isset($_SESSION['wop_admin_user']) ? $_SESSION['wop_admin_user'] : '';
empty(!$user) && header('Location: ./admin.php');

?>
Expand Down
2 changes: 1 addition & 1 deletion verify.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

session_start();
$user = $_SESSION['wop_admin_user'];
$user = isset($_SESSION['wop_admin_user']) ? $_SESSION['wop_admin_user'] : '';
empty($user) && header('Location: ./login.php');

?>
Expand Down

0 comments on commit e51e125

Please sign in to comment.