Uzaktan Veri Çekimi Sorunu Php
-
<?php include('ip2locationlite.class.php'); //Load the class $ipLite = new ip2location_lite; $ipLite->setKey('<your_api_key>'); //Get errors and locations $locations = $ipLite->getCity($_SERVER['REMOTE_ADDR']); $errors = $ipLite->getError(); //Getting the result echo "<p>\n"; echo "<strong>First result</strong><br />\n"; if (!empty($locations) && is_array($locations)) { foreach ($locations as $field => $val) { echo $field . ' : ' . $val . "<br />\n"; } } echo "</p>\n"; //Show errors echo "<p>\n"; echo "<strong>Dump of all errors</strong><br />\n"; if (!empty($errors) && is_array($errors)) { foreach ($errors as $error) { echo var_dump($error) . "<br /><br />\n"; } } else { echo "No errors" . "<br />\n"; } echo "</p>\n";
Test php
<?php final class ip2location_lite{ protected $errors = array(); protected $service = 'api.ipinfodb.com'; protected $version = 'v3'; protected $apiKey = ''; public function __construct(){} public function __destruct(){} public function setKey($key){ if(!empty($key)) $this->apiKey = $key; } public function getError(){ return implode("\n", $this->errors); } public function getCountry($host){ return $this->getResult($host, 'ip-country'); } public function getCity($host){ return $this->getResult($host, 'ip-city'); } private function getResult($host, $name){ $ip = @gethostbyname($host); if(preg_match('/^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:[.](?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$/', $ip)){ $xml = @file_get_contents('http://' . $this->service . '/' . $this->version . '/' . $name . '/?key=' . $this->apiKey . '&ip=' . $ip . '&format=xml'); try{ $response = @new SimpleXMLElement($xml); foreach($response as $field=>$value){ $result[(string)$field] = (string)$value; } return $result; } catch(Exception $e){ $this->errors[] = $e->getMessage(); return; } } $this->errors[] = '"' . $host . '" is not a valid IP address or hostname.'; return; } } ?>fonksiyon.phpbeyler bu zımbırtı localde çalışıyor sorunsuz ama sunucuya atınca karşı makineden veri çekmiyor curl aktif sunucuda -
EcHoLL bunu yazdı
\n"; if (!empty($locations) && is_array($locations)) { foreach ($locations as $field => $val) { echo $field . ' : ' . $val . "
\n"; } } echo "\n"; //Show errors echo "\n"; echo "Dump of all errors
\n"; if (!empty($errors) && is_array($errors)) { foreach ($errors as $error) { echo var_dump($error) . "
\n"; } } else { echo "No errors" . "
\n"; } echo "\n";
Test php
fonksiyon.phpbeyler bu zımbırtı localde çalışıyor sorunsuz ama sunucuya atınca karşı makineden veri çekmiyor curl aktif sunucudaerror log yok mu hocam
-
First result
Dump of all errors
No errorserror vermiyor ne yazıkki file_get ile çekmiyor sanırım localde sorunsuz çalışıyor
-
Curl ile veri çekimi çalışıyor sunucuda file_get kapalı fonksiyonlardan bunu curl olarak editlemek lazım
-
bu fonksiyon php dosyasını curl ile çalışır hale getiricek bir arkadaş lazım bana :)
-
http://www.jonasjohn.de/snippets/php/curl-example.htm
function curl_download($Url){ // is cURL installed yet? if (!function_exists('curl_init')){ die('Sorry cURL is not installed!'); } // OK cool - then let's create a new cURL resource handle $ch = curl_init(); // Now set some options (most are optional) // Set URL to download curl_setopt($ch, CURLOPT_URL, $Url); // Set a referer curl_setopt($ch, CURLOPT_REFERER, "http://www.example.org/yay.htm"); // User agent curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0"); // Include header in result? (0 = yes, 1 = no) curl_setopt($ch, CURLOPT_HEADER, 0); // Should cURL return or print out the data? (true = return, false = print) curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Timeout in seconds curl_setopt($ch, CURLOPT_TIMEOUT, 10); // Download the given URL, and return output $output = curl_exec($ch); // Close the cURL resource, and free system resources curl_close($ch); return $output; }$xml = @file_get_contents('http://' . $this->service . '/' . $this->version . '/' . $name . '/?key=' . $this->apiKey . '&ip=' . $ip . '&format=xml');
bunun yerine
$xml = curl_download('http://' . $this->service . '/' . $this->version . '/' . $name . '/?key=' . $this->apiKey . '&ip=' . $ip . '&format=xml');
kullanmayı dener misin?
-
$xml = file_get_contents() kısmını aşağıdaki kod ile değiştirebilirsin. fonksiyon başına @ işareti koyduğun için hata kodu üretmiyor.
$xmlUrl = 'http://' . $this->service . '/' . $this->version . '/' . $name . '/?key=' . $this->apiKey . '&ip=' . $ip . '&format=xml';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $xmlUrl
));
$xml = curl_exec($curl);
curl_close($curl);
-
Sağollasınız Arkadaşlar deniyorum şimdi yazarım
-
ManiakRhifat bunu yazdı
$xml = file_get_contents() kısmını aşağıdaki kod ile değiştirebilirsin. fonksiyon başına @ işareti koyduğun için hata kodu üretmiyor.
$xmlUrl = 'http://' . $this->service . '/' . $this->version . '/' . $name . '/?key=' . $this->apiKey . '&ip=' . $ip . '&format=xml';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $xmlUrl
));
$xml = curl_exec($curl);
curl_close($curl);
senin gönerdiğin fonksiyon çalıştı
fonksiyonun curl ile çalışır hali https://ghostbin.com/paste/sj43y lazım olanlar kullanır
