matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 1 | <?php |
| 2 | function generateRandomString($length = 96) { |
| 3 | $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
| 4 | $charactersLength = strlen($characters); |
| 5 | $randomString = ''; |
| 6 | for ($i = 0; $i < $length; $i++) { |
| 7 | $randomString .= $characters[rand(0, $charactersLength - 1)]; |
| 8 | } |
| 9 | return $randomString; |
| 10 | } |
| 11 | |
| 12 | function getClientIP():string |
| 13 | { |
| 14 | $keys=array('HTTP_CLIENT_IP','HTTP_X_FORWARDED_FOR','HTTP_X_FORWARDED','HTTP_FORWARDED_FOR','HTTP_FORWARDED','REMOTE_ADDR'); |
| 15 | foreach($keys as $k) |
| 16 | { |
| 17 | if (!empty($_SERVER[$k]) && filter_var($_SERVER[$k], FILTER_VALIDATE_IP)) |
| 18 | { |
| 19 | return $_SERVER[$k]; |
| 20 | } |
| 21 | } |
| 22 | return false; |
| 23 | } |
| 24 | ?> |