Skip to content

Instantly share code, notes, and snippets.

@Sentinel-7
Created June 24, 2021 08:13
Show Gist options
  • Save Sentinel-7/798c524bfa9a2111b38c21a062df2854 to your computer and use it in GitHub Desktop.
Save Sentinel-7/798c524bfa9a2111b38c21a062df2854 to your computer and use it in GitHub Desktop.
getIp определяем ip пользователя
/*
<input type="hidden" name="{$formID}_ip" value="{'!getIP' | snippet}" />
*/
<?php
if (!function_exists('getIp')) {
function getIp() {
$keys = [
'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'REMOTE_ADDR'
];
foreach ($keys as $key) {
if (!empty($_SERVER[$key])) {
$ip = trim(end(explode(',', $_SERVER[$key])));
if (filter_var($ip, FILTER_VALIDATE_IP)) {
return $ip;
}
}
}
}
$ip = getIp();
// выведем IP клиента на экран
echo $ip;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment