• 28-04-2013, 10:39:27
    #1
    Merhaba Arkadaşlar,

    aşağıdaki sistemi çalıştırdıgımda else'e düşüyorum problem nerde acaba yardımıcı olabilriseniz sevinirim.

    <?php 
    $ipaddress = $_SERVER['REMOTE_ADDR']; 
    $locationstr = "http:api.locatorhq.com/?user=aaaz2568&key=cb70014a000193e4a21f8c5d546128d7ce231dae&ip=".$ipaddress."&format=xml"; 
      
    $xml = simplexml_load_file($locationstr); 
    
    $country = $xml->countryCode; 
    echo $country; 
    
    if (eregi ("TR", $country)) {   
    header("Location:http://tr.siteadi.com"); 
    } 
    elseif (eregi ("ES", $country)) {   
    header("Location:http://es.siteadi.com"); 
    } 
    elseif (eregi ("DE", $country)) {   
    header("Location:http://de.siteadi.com"); 
    } 
    elseif (eregi ("FR", $country)) {   
    header("Location:http://fr.siteadi.com"); 
    } 
    elseif (eregi ("JP", $country)) {   
    header("Location:http://jp.siteadi.com"); 
    } 
    elseif (eregi ("UK", $country)) {   
    header("Location:http://uk.siteadi.com"); 
    } 
    elseif (eregi ("MX", $country)) {   
    header("Location:http://mx.siteadi.com"); 
    } 
    elseif (eregi ("NL", $country)) {   
    header("Location:http://nl.siteadi.com"); 
    } 
    elseif (eregi ("RU", $country)) {   
    header("Location:http://ru.siteadi.com"); 
    } 
    elseif (eregi ("BE", $country)) {   
    header("Location:http://be.siteadi.com"); 
    } 
    else { echo "olmadi";}
    ?>
  • 28-04-2013, 22:14:34
    #2
    güncel. yardımcı olabilecek varmı arkadaşlar ?
  • 28-04-2013, 23:31:44
    #3
    "Warning This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged."

    eregi fonksiyonu php 5.3.0 kaldırılmış bir fonksiyondur muhtemelen sunucunuz eski bir php sürümü desteklemiyorsa sıkıntı bundan kaynaklanıyor eregi yerine preg_match kullanın bu işlem içinde strrrpos kullanmanızı öneririm
  • 29-04-2013, 00:21:47
    #4
    Kodda sadece iki şey değiştirdim ve tr.siteadi.com sayfasına yönlendi.

    1. değiştirdiğim şey ip adresi oldu. $_SERVER['REMOTE_ADDR'] demişsiniz, bunu manuel olarak kendi internete bağlandığım ip adresiyle değiştirdim. İkincisi ise verdiğiniz adres. Bilmiyorum kodu buraya yazarken özellikle mi öyle yaptınız ama http: dan sonra iki tane slash koydum. Yani http://api..... şeklinde Sorun olmadan çalıştı.

    NOT: localhostta çalıştırırsanız else bloğunun çalışması normaldir. Çünkü IP adresini 127.0.0.1 olarak alır. Ya da Windows 7 ve üstünde ip adresi ::1 şeklinde döner. Bu yüzden web sayfası NO DATA şeklinde bir sonuç dönderiyor. NO DATA sonucu yüzünden else bloğuna düşüyorsunuz.

    <?php
     
    $ipaddress = "78.191.101.234";
    $locationstr = "http://api.locatorhq.com/?user=aaaz2568&key=cb70014a000193e4a21f8c5d546128d7ce231dae&ip=".$ipaddress."&format=xml";  
       
    $xml = simplexml_load_file($locationstr);  
    
    $country = $xml->countryCode;  
    echo $country;  
    
    if (eregi ("TR", $country)) {    
    header("Location:http://tr.siteadi.com");  
    }  
    elseif (eregi ("ES", $country)) {    
    header("Location:http://es.siteadi.com");  
    }  
    elseif (eregi ("DE", $country)) {    
    header("Location:http://de.siteadi.com");  
    }  
    elseif (eregi ("FR", $country)) {    
    header("Location:http://fr.siteadi.com");  
    }  
    elseif (eregi ("JP", $country)) {    
    header("Location:http://jp.siteadi.com");  
    }  
    elseif (eregi ("UK", $country)) {    
    header("Location:http://uk.siteadi.com");  
    }  
    elseif (eregi ("MX", $country)) {    
    header("Location:http://mx.siteadi.com");  
    }  
    elseif (eregi ("NL", $country)) {    
    header("Location:http://nl.siteadi.com");  
    }  
    elseif (eregi ("RU", $country)) {    
    header("Location:http://ru.siteadi.com");  
    }  
    elseif (eregi ("BE", $country)) {    
    header("Location:http://be.siteadi.com");  
    }  
    else { echo "olmadi";} 
    ?>
  • 29-04-2013, 11:25:53
    #5
    $_SERVER['REMOTE_ADDR'];

    yazarak localde değil hostta çalısıyorum ama else bloguna düşüyor hocam // olayını mühim değil

    --R10.NET; Flood Engellendi -->-> Yeni yazılan mesaj 11:25:53 -->-> Daha önceki mesaj 11:04:12 --

    <?php 
      
    $ipaddress = $_SERVER['REMOTE_ADDR'];
    $locationstr = "http://api.locatorhq.com/?user=aaaz2568&key=cb70014a000193e4a21f8c5d546128d7ce231dae&ip=".$ipaddress."&format=xml";   
        echo $locationstr;
    $xml = simplexml_load_file($locationstr);   
    
    $country = $xml->countryCode;   
    print_r($country);   
    
    
    ?>
    bu şekilde test ettim $country değişkenini çalıştırmıyor.
  • 29-04-2013, 11:54:57
    #6
    Verdiğiniz bu kod bende şu sonucu veriyor:

    SimpleXMLElement Object ( [0] => TR )
    Bu duruma neden olabilecekler :
    • $_SERVER['REMOTE_ADDR'] ile aldığınız ip adresi, api ile bağlantı kurduğunuz sitenin veritabanında yoksa NO DATA dönüyor. Bu yüzden else bloğuna düşüyor olabilirsiniz.
    • Ben sunucumun ip adresini yazdım, ip adresi doğru ve bir çok ip tracker sitede ülkeyi veriyor. Ancak bu sitede NO DATA sonucunu verdi
    • Sonuç string olduğunda, simplexml_load_file fonksiyonunun bir sonuç döndürmesini beklemeyin
    • Sunucunuzda default olarak simplexml_load_file deaktif durumda olabilir, kontrol edin. Normalde ön tanımlı gelir ancak deaktif edilmiş olabilir.


    Bu liste sonuç vermezse bir de tarayıcınızda şu adresi çalıştırın ve sonucu buraya yazın:

    http://api.locatorhq.com/?user=aaaz2...234&format=xml

    BLaH adlı üyeden alıntı: mesajı görüntüle
    $_SERVER['REMOTE_ADDR'];

    yazarak localde değil hostta çalısıyorum ama else bloguna düşüyor hocam // olayını mühim değil

    --R10.NET; Flood Engellendi -->-> Yeni yazılan mesaj 11:25:53 -->-> Daha önceki mesaj 11:04:12 --

    <?php 
      
    $ipaddress = $_SERVER['REMOTE_ADDR'];
    $locationstr = "http://api.locatorhq.com/?user=aaaz2568&key=cb70014a000193e4a21f8c5d546128d7ce231dae&ip=".$ipaddress."&format=xml";   
        echo $locationstr;
    $xml = simplexml_load_file($locationstr);   
    
    $country = $xml->countryCode;   
    print_r($country);   
    
    
    ?>
    bu şekilde test ettim $country değişkenini çalıştırmıyor.
  • 29-04-2013, 12:39:13
    #7
    <ip2locationapi>
    <countryCode>TR</countryCode>
    <countryName>Turkey</countryName>
    <region>Istanbul</region>
    <city>Istanbul</city>
    <latitude>41.0186</latitude>
    <longitude>28.9647</longitude>
    </ip2locationapi>

    tarayıcıda çalıstırdığımda ki sonuç bu.

    SimpleXML

    Simplexml support enabled
    Revision $Revision: 299424 $
    Schema support enabled

    SimpleXml enabled durumda
  • 29-04-2013, 12:47:44
    #8
    BLaH adlı üyeden alıntı: mesajı görüntüle
    <ip2locationapi>
    <countryCode>TR</countryCode>
    <countryName>Turkey</countryName>
    <region>Istanbul</region>
    <city>Istanbul</city>
    <latitude>41.0186</latitude>
    <longitude>28.9647</longitude>
    </ip2locationapi>

    tarayıcıda çalıstırdığımda ki sonuç bu.

    SimpleXML

    Simplexml support enabled
    Revision $Revision: 299424 $
    Schema support enabled

    SimpleXml enabled durumda
    Bu sonuç çıkıyorsa, simplexml_load_file seçeneğinin çalışmaması için bir neden yok. Öyleyse bir de şunu yapın.

    Önce echo $_SERVER['REMOTE_ADDR']; diyerek hostunuzda çalıştırın. Ekranda çıkan ip adresini alın ve şu url de IP_ADRESI yazan yere elle yazın:

    <?php 
      
    $ipaddress = "IP_ADRESI"; 
    $locationstr = "http://api.locatorhq.com/?user=aaaz2568&key=cb70014a000193e4a21f8c5d546128d7ce231dae&ip=".$ipaddress."&format=xml";   
        
    $xml = simplexml_load_file($locationstr);   
    
    print_r($xml);
    Eğer herhangi bir hata varsa, bu şekilde de bir sonuç döndürmemesi lazım ama bende şunu dönderiyor:

    SimpleXMLElement Object ( [countryCode] => TR [countryName] => Turkey [region] => Istanbul [city] => Istanbul [latitude] => 41.0186 [longitude] => 28.9647 )

    Sizde de buna benzer bir sonuç dönmeli.
  • 29-04-2013, 12:57:20
    #9
    json daha basit değil mi?

    http://api.locatorhq.com/?user=aaaz2...34&format=json

    <?php
    $ipaddress = $_SERVER['REMOTE_ADDR'];   
    $locationstr = @json_decode(file_get_contents("http://api.locatorhq.com/?user=aaaz2568&key=cb70014a000193e4a21f8c5d546128d7ce231dae&ip=".$ipaddress."&format=json"),1);   
    
    $ulkeler=array("TR"=>"http://tr.x.com","DE"=>"http://de.x.com"); 
    echo $locationstr["countryCode"];
    if($ulkeler[$locationstr["countryCode"]])
    { 
    header("Location: ".$ulkeler[$locationstr["countryCode"]]);exit; 
    } 
    else 
    { 
    echo ":("; 
    }