Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
wxh_internal_api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
杨培培
wxh_internal_api
Commits
012219d4
Commit
012219d4
authored
May 04, 2018
by
杨培
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
客户端请求时将透传IP与代理信息,以确保服务方可以获取到正确的IP地址
parent
cf50211b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
1 deletion
+15
-1
Client.php
src/base/Client.php
+15
-1
No files found.
src/base/Client.php
View file @
012219d4
...
...
@@ -184,6 +184,20 @@ class Client
CURLOPT_USERAGENT
=>
$userAgent
]);
//IP 透传
if
(
isset
(
$_SERVER
[
'REMOTE_ADDR'
]))
{
$clientIp
=
!
empty
(
$_SERVER
[
'HTTP_CLIENT_IP'
])
?
$_SERVER
[
'HTTP_CLIENT_IP'
]
:
$_SERVER
[
'REMOTE_ADDR'
];
$headers
[]
=
'Client-IP: '
.
$clientIp
;
$forwardedFor
=
!
empty
(
$_SERVER
[
'HTTP_X_FORWARDED_FOR'
])
?
$_SERVER
[
'HTTP_X_FORWARDED_FOR'
]
:
(
$_SERVER
[
'REMOTE_ADDR'
]
!=
$_SERVER
[
'SERVER_ADDR'
]
?
$_SERVER
[
'REMOTE_ADDR'
]
:
''
);
if
(
$forwardedFor
&&
$forwardedFor
!=
$clientIp
)
{
$forwardedFor
.=
','
.
$_SERVER
[
'SERVER_ADDR'
];
$headers
[]
=
'X-Forwarded-For: '
.
$forwardedFor
;
}
}
//POST 请求
if
(
$post
)
{
$body
=
is_array
(
$post
)
?
http_build_query
(
$post
)
:
$post
;
...
...
@@ -194,7 +208,7 @@ class Client
}
//优化
$headers
[]
=
'Expect:'
;
$headers
[]
=
'Expect:
'
;
curl_setopt_array
(
$ci
,
[
CURLOPT_HTTPHEADER
=>
$headers
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment