requestStack = $requestStack; $this->geoApiUrl = $geoApiUrl; $this->geoApiKey = $geoApi; } public function getInfo(){ $info = array(); $info['ip'] = $this->getIp(); $info['geolocalisation'] = $this->geolocIp($info['ip']); return $info; } public function getIp(){ return $this->requestStack->getCurrentRequest()->getClientIp(); } private function geolocIp($ip){ $url = $this->geoApiUrl.$ip."?key=".$this->geoApiKey; $ch = curl_init(); // Disable SSL verification curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Will return the response, if false it print the response curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Set the url curl_setopt($ch, CURLOPT_URL,$url); // Execute $result=curl_exec($ch); // Closing curl_close($ch); return json_decode($result, true); } /** * Check if host is self called * * @param bool $disallowProxy * @return bool */ public function isSelfCalled($disallowProxy = false){ if($disallowProxy){ $xf = $this->requestStack->getCurrentRequest()->headers->get('X-Forwarded-For',1010); if($xf != 1010) return false; } $ch = curl_init($_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].'/workers/app/self-ip.php'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); $localIp = curl_exec($ch); curl_close($ch); return ($this->getIp() === $localIp); } }