ghttp.Request增加获取用户真实IP判断

This commit is contained in:
john
2018-08-31 18:51:45 +08:00
parent 32993c37f6
commit 786402ca7e

View File

@ -168,11 +168,13 @@ func (r *Request) IsAjaxRequest() bool {
func (r *Request) GetClientIp() string {
ip := r.clientIp.Val()
if len(ip) == 0 {
array, _ := gregex.MatchString(`(.+):(\d+)`, r.RemoteAddr)
if len(array) > 1 {
ip = array[1]
} else {
ip = r.RemoteAddr
if ip = r.Header.Get("X-Real-IP"); ip == "" {
array, _ := gregex.MatchString(`(.+):(\d+)`, r.RemoteAddr)
if len(array) > 1 {
ip = array[1]
} else {
ip = r.RemoteAddr
}
}
r.clientIp.Set(ip)
}