diff options
| author | jvoisin | 2020-07-12 19:19:41 +0200 |
|---|---|---|
| committer | jvoisin | 2020-07-12 19:20:34 +0200 |
| commit | 05c98eb39f07bd951b6047e154db6479828e2a11 (patch) | |
| tree | 7256400b1d2a9875632e34f532ef3a2fbc513b9d /src | |
| parent | ae96df0cae20ccb1225a0dc305b4779427506608 (diff) | |
Use $_SERVER['REMOTE_ADDR'] in last resort to get the client's ip addr
Diffstat (limited to 'src')
| -rw-r--r-- | src/sp_utils.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/sp_utils.c b/src/sp_utils.c index 8c64b55..e5c2942 100644 --- a/src/sp_utils.c +++ b/src/sp_utils.c | |||
| @@ -19,6 +19,24 @@ const char* get_ipaddr() { | |||
| 19 | return fwd_ip; | 19 | return fwd_ip; |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | /* Some hosters (like heroku, see | ||
| 23 | * https://github.com/jvoisin/snuffleupagus/issues/336) are clearing the | ||
| 24 | * environment variables, so we don't have access to them, hence why we're | ||
| 25 | * resorting to $_SERVER['REMOTE_ADDR']. | ||
| 26 | */ | ||
| 27 | if (!Z_ISUNDEF(PG(http_globals)[TRACK_VARS_SERVER])) { | ||
| 28 | const zval* const globals_client_ip = | ||
| 29 | zend_hash_str_find(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), | ||
| 30 | "REMOTE_ADDR", sizeof("REMOTE_ADDR") - 1); | ||
| 31 | if (globals_client_ip) { | ||
| 32 | if (Z_TYPE_P(globals_client_ip) == IS_STRING) { | ||
| 33 | if (Z_STRLEN_P(globals_client_ip) != 0) { | ||
| 34 | return estrdup(Z_STRVAL_P(globals_client_ip)); | ||
| 35 | } | ||
| 36 | } | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 22 | return default_ipaddr; | 40 | return default_ipaddr; |
| 23 | } | 41 | } |
| 24 | 42 | ||
