viernes, 25 de enero de 2013

PHP - capturar el IP del cliente

Adjunto un script muy necesario para poder extraer el IP del cliente, que incluye validaciones de red interna, host local y redirecciones:
function getIp()
    {
        if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) 
     AND $_SERVER['HTTP_X_FORWARDED_FOR'] 
     AND (!isset($_SERVER['REMOTE_ADDR']) 
     OR preg_match('/^127\..*/i', trim($_SERVER['REMOTE_ADDR'])) 
     OR preg_match('/^172\.16.*/i', trim($_SERVER['REMOTE_ADDR'])) 
     OR preg_match('/^192\.168\.*/i', trim($_SERVER['REMOTE_ADDR'])) 
     OR preg_match('/^10\..*/i', trim($_SERVER['REMOTE_ADDR'])))) {
                $ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
                return $ips[0];
        }
        return $_SERVER['REMOTE_ADDR'];
    }

Configure Grafana and Slack

To configure Grafana to send alerts to Slack, you need to set up a notification channel in Grafana and configure it to use the Slack integra...