forked from zhufenghua1998/bp3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopen.php
More file actions
58 lines (51 loc) · 1.75 KB
/
Copy pathopen.php
File metadata and controls
58 lines (51 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
session_start();
$user = $_SESSION['user'];
$configfile = "./config.php";
require($configfile);
require_once("functions.php");
function getip()
{
//客户端IP 或 NONE
$ip = false;
if (!empty($_SERVER["HTTP_CLIENT_IP"])) {
$ip = $_SERVER["HTTP_CLIENT_IP"];
}
//多重代理服务器下的客户端真实IP地址(可能伪造),如果没有使用代理,此字段为空
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ips = explode(", ", $_SERVER['HTTP_X_FORWARDED_FOR']);
if ($ip) {
array_unshift($ips, $ip);
$ip = FALSE;
}
for ($i = 0; $i < count($ips); $i++) {
if (!preg_match("/^(10│172.16│192.168)./i", $ips[$i])) {
$ip = $ips[$i];
break;
}
}
}
return ($ip ? $ip : $_SERVER['REMOTE_ADDR']);
}
$remote_ip = getip();
// getServerIp
$server_hostname=$_SERVER['SERVER_NAME'];
$server_ip=gethostbyname($server_hostname);
if($remote_ip == $server_ip){
// 获取当前路径
$page_url = getPageUrl();
$page_url = str_replace("/open.php","",$page_url);
$refresh_url = $page_url."/admin/refresh_token.php";
//自动刷新token
$access_token = get_token_refresh($config,$refresh_url);
if(!$access_token){
require($configfile);
echo $config['identify']['access_token'];
}else{
echo $access_token;
}
}else if($user){
// 存在session情况下,也可以直接访问本页面获取token
echo $config['identify']['access_token'];
}
?>