curl

geo ip example

28.01.2016 php скрипты , ,

<?
$ip = '192.168.11.5';
if($ch = curl_init()){		
	$url = "http://freegeoip.net/json/". $ip; 
	$headers = array(
		"Content-type: application/json",
		"Accept: application/json",
		"Accept-Language:ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4"
	); 
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL,$url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);	
 
	$data = curl_exec($ch); 
 
	if (curl_errno($ch)) {

		// curl_error($ch);         

	  
	} else {		         
		$arData = json_decode($data, true) ; 
	}
	
	curl_close($ch);  
}
print_r($arData);
?>

Curl для dadata.ru

07.10.2015 php, php скрипты

       $url = "https://dadata.ru/api/v2/suggest/address"; 
     
        $headers = array( 
            "Content-type: application/json", 
            "Accept: application/json", 
			"Authorization: Token ДЛИННЫЙ_КЛЮЧ" 
        ); 
       
        $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL,$url); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt($ch, CURLOPT_TIMEOUT, 60); 
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru-RU"); 

        curl_setopt($ch, CURLOPT_POST, 1); 
        curl_setopt($ch, CURLOPT_POSTFIELDS, '{ "query": "Москва Площадь Ленина 5 6", "count": 5 }'); 

        $data = curl_exec($ch); 
		
		

        if (curl_errno($ch)) { 
		
			echo  "Error: " . curl_error($ch);			
         
			
        } else { 
		
			curl_close($ch);			
			echo json_decode($data, true);	
        }