• 04-05-2018, 11:42:34
    #1
    Merhabalar,

    Arkadaşlar siteye giren ziyaretçilerin ip adresleri lokasyonları zaman gibi verileri log tutmak istiyorum bir kod buldum aslında fakat kodu siteye eklediğimde veri yazma yapıyor ama sadece zaman yazıyor diğer verileri çekmiyor. Kodu aşağıda paylaşıyorum acaba sıkıntı nerede nasıl düzeltiriz yardımcı olan olursa çok sevinirim.

    <?php
     
    session_start();
     
    // ## KULLANICININ DOĞRU İP ADRESİNİ ÖĞRENELİM!
    function ipogrenme(){
    if(getenv("HTTP_CLIENT_IP")){
    $ip = getenv("HTTP_CLIENT_IP");
    }else if(getenv("HTTP_X_FORWARDED_FOR")){
    $ip = getenv("HTTP_X_FORWARDED_FOR");
    if(strstr($ip, ',')) {
    $tmp = explode (',', $ip);
    $ip = trim($tmp[0]);
    }
    }else{
    $ip = getenv("REMOTE_ADDR");
    }
    return $ip;
    }
    // ## LOG DOSYASI YAZALIM
    function logla($logmetin){
    $dosya = 'log.html';
    $metin = date('d-m-Y h:i - ').$logmetin.'<br/>';
    $fh = fopen($dosya, 'a+') or die('Hata!');
    fwrite($fh, $metin);
    fclose($fh);
    $_SESSION['ipadreskayit'] = true;
    }
     
    // ## ŞEHİR BİLGİSİNİ BULALIM
    if(!isset($_SESSION['ipadreskayit'])){
    function sehir_bul($ip){
    $default = 'Bilinmiyor';
    if (!is_string($ip) || strlen($ip) < 1 || $ip == '127.0.0.1' || $ip == 'localhost'){
    $ip = '8.8.8.8';
    }
    $curlopt_useragent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36';
    $url = 'http://www.ipsorgu.com/?ip=' . urlencode($ip) . '#sorgu';
    $ch = curl_init();
    $curl_opt = array(
    CURLOPT_FOLLOWLOCATION => 1,
    CURLOPT_HEADER => 0,
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_USERAGENT => $curlopt_useragent,
    CURLOPT_URL => $url,
    CURLOPT_TIMEOUT => 1,
    CURLOPT_REFERER => 'http://' . $_SERVER['HTTP_HOST'],
    );
    curl_setopt_array($ch, $curl_opt);
    $content = curl_exec($ch);
    curl_close($ch);
     
    if(preg_match('#<title>(.*?)</title>#', $content, $regs)){
    $city = $regs[1];
    }
    if($city != ''){
    $metin = explode('-', $city);
    logla($metin[0]);
    }else{
    return $default;
    }
    }
    sehir_bul(ipogrenme());
    }
     
    ?>
    • Belirtilen log dosyasına kaydeder. (log.html)
  • 04-05-2018, 12:07:26
    #2
    <?php
     
    session_start();
     
    // ## KULLANICININ DOĞRU İP ADRESİNİ ÖĞRENELİM!
    function ipogrenme(){
    if(getenv("HTTP_CLIENT_IP")){
    $ip = getenv("HTTP_CLIENT_IP");
    }else if(getenv("HTTP_X_FORWARDED_FOR")){
    $ip = getenv("HTTP_X_FORWARDED_FOR");
    if(strstr($ip, ',')) {
    $tmp = explode (',', $ip);
    $ip = trim($tmp[0]);
    }
    }else{
    $ip = getenv("REMOTE_ADDR");
    }
    return $ip;
    }
    // ## LOG DOSYASI YAZALIM
    function logla($logmetin){
    $dosya = 'log.html';
    $metin = date('d-m-Y h:i - ').$logmetin.'<br/>';
    $fh = fopen($dosya, 'a+') or die('Hata!');
    fwrite($fh, $metin);
    fclose($fh);
    $_SESSION['ipadreskayit'] = true;
    }
     
    // ## ŞEHİR BİLGİSİNİ BULALIM
    if(!isset($_SESSION['ipadreskayit'])){
    function sehir_bul($ip){
    $default = 'Bilinmiyor';
    if (!is_string($ip) || strlen($ip) < 1 || $ip == '127.0.0.1' || $ip == 'localhost'){
    $ip = '8.8.8.8';
    }
    $curlopt_useragent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36';
    $url = 'http://www.ipsorgu.com/?ip=' . urlencode($ip) . '#sorgu';
    $ch = curl_init();
    $curl_opt = array(
    CURLOPT_FOLLOWLOCATION => 1,
    CURLOPT_HEADER => 0,
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_USERAGENT => $curlopt_useragent,
    CURLOPT_URL => $url,
    CURLOPT_TIMEOUT => 1,
    CURLOPT_REFERER => 'http://' . $_SERVER['HTTP_HOST'],
    );
    curl_setopt_array($ch, $curl_opt);
    $content = curl_exec($ch);
    curl_close($ch);
     
    if(preg_match('#<title>(.*?)</title>#', $content, $regs)){
    $city=explode("-", $regs[1]);
    $city=trim($city[0]);
    }
    if($city != ''){
    logla($city);
    }else{
    return $default;
    }
    }
    sehir_bul(ipogrenme());
    }
     
    ?>
  • 04-05-2018, 12:16:23
    #3
    php_bot adlı üyeden alıntı: mesajı görüntüle
    <?php
     
    session_start();
     
    // ## KULLANICININ DOĞRU İP ADRESİNİ ÖĞRENELİM!
    function ipogrenme(){
    if(getenv("HTTP_CLIENT_IP")){
    $ip = getenv("HTTP_CLIENT_IP");
    }else if(getenv("HTTP_X_FORWARDED_FOR")){
    $ip = getenv("HTTP_X_FORWARDED_FOR");
    if(strstr($ip, ',')) {
    $tmp = explode (',', $ip);
    $ip = trim($tmp[0]);
    }
    }else{
    $ip = getenv("REMOTE_ADDR");
    }
    return $ip;
    }
    // ## LOG DOSYASI YAZALIM
    function logla($logmetin){
    $dosya = 'log.html';
    $metin = date('d-m-Y h:i - ').$logmetin.'<br/>';
    $fh = fopen($dosya, 'a+') or die('Hata!');
    fwrite($fh, $metin);
    fclose($fh);
    $_SESSION['ipadreskayit'] = true;
    }
     
    // ## ŞEHİR BİLGİSİNİ BULALIM
    if(!isset($_SESSION['ipadreskayit'])){
    function sehir_bul($ip){
    $default = 'Bilinmiyor';
    if (!is_string($ip) || strlen($ip) < 1 || $ip == '127.0.0.1' || $ip == 'localhost'){
    $ip = '8.8.8.8';
    }
    $curlopt_useragent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36';
    $url = 'http://www.ipsorgu.com/?ip=' . urlencode($ip) . '#sorgu';
    $ch = curl_init();
    $curl_opt = array(
    CURLOPT_FOLLOWLOCATION => 1,
    CURLOPT_HEADER => 0,
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_USERAGENT => $curlopt_useragent,
    CURLOPT_URL => $url,
    CURLOPT_TIMEOUT => 1,
    CURLOPT_REFERER => 'http://' . $_SERVER['HTTP_HOST'],
    );
    curl_setopt_array($ch, $curl_opt);
    $content = curl_exec($ch);
    curl_close($ch);
     
    if(preg_match('#<title>(.*?)</title>#', $content, $regs)){
    $city=explode("-", $regs[1]);
    $city=trim($city[0]);
    }
    if($city != ''){
    logla($city);
    }else{
    return $default;
    }
    }
    sehir_bul(ipogrenme());
    }
     
    ?>
    Öncelikle teşekkür ederim hocam. Kodları sitedeki gerekli yere koydum fakat sayfa açılmadı. test etmek için test.php sayfası oluşturup denedim sayfa yine açılması şu şekilde hata verdi. http://prntscr.com/jdl22t
  • 04-05-2018, 12:33:45
    #4
    Bu şekilde denermisin birde suncuda denedim çalışıyor.
    <?php
    
    session_start();
    
    // ## KULLANICININ DOĞRU İP ADRESİNİ ÖĞRENELİM!
    function ipogrenme(){
    if(getenv("HTTP_CLIENT_IP")){
    $ip = getenv("HTTP_CLIENT_IP");
    }else if(getenv("HTTP_X_FORWARDED_FOR")){
    $ip = getenv("HTTP_X_FORWARDED_FOR");
    if(strstr($ip, ',')) {
    $tmp = explode (',', $ip);
    $ip = trim($tmp[0]);
    }
    }else{
    $ip = getenv("REMOTE_ADDR");
    }
    return $ip;
    }
    // ## LOG DOSYASI YAZALIM
    function logla($logmetin){
    $dosya = 'log.html';
    $metin = date('d-m-Y h:i - ').$logmetin.'<br/>';
    $fh = fopen($dosya, 'a+') or die('Hata!');
    fwrite($fh, $metin);
    fclose($fh);
    $_SESSION['ipadreskayit'] = true;
    }
    
    // ## ŞEHİR BİLGİSİNİ BULALIM
    if(!isset($_SESSION['ipadreskayit'])){
    function sehir_bul($ip){
    $default = 'Bilinmiyor';
    if (!is_string($ip) || strlen($ip) < 1 || $ip == '127.0.0.1' || $ip == 'localhost'){
    $ip = '8.8.8.8';
    }
    $curlopt_useragent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36';
    $url = 'http://www.ipsorgu.com/?ip=' . urlencode($ip) . '#sorgu';
    $ch = curl_init();
    $curl_opt = array(
    CURLOPT_FOLLOWLOCATION => 1,
    CURLOPT_HEADER => 0,
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_USERAGENT => $curlopt_useragent,
    CURLOPT_URL => $url,
    CURLOPT_TIMEOUT => 1,
    CURLOPT_REFERER => 'http://' . $_SERVER['HTTP_HOST'],
    );
    curl_setopt_array($ch, $curl_opt);
    $content = curl_exec($ch);
    curl_close($ch);
    
    if(preg_match('#<title>(.*?)</title>#', $content, $regs)){
    $city=$regs[1];
    }
    if($city != ''){
    $city=explode("-", $city);
    $city=trim($city[0]);
    logla($city);
    }else{
    return $default;
    }
    }
    sehir_bul(ipogrenme());
    }
    
    ?>
  • 04-05-2018, 12:39:42
    #5
    php_bot adlı üyeden alıntı: mesajı görüntüle
    Bu şekilde denermisin birde suncuda denedim çalışıyor.
    <?php
    
    session_start();
    
    // ## KULLANICININ DOĞRU İP ADRESİNİ ÖĞRENELİM!
    function ipogrenme(){
    if(getenv("HTTP_CLIENT_IP")){
    $ip = getenv("HTTP_CLIENT_IP");
    }else if(getenv("HTTP_X_FORWARDED_FOR")){
    $ip = getenv("HTTP_X_FORWARDED_FOR");
    if(strstr($ip, ',')) {
    $tmp = explode (',', $ip);
    $ip = trim($tmp[0]);
    }
    }else{
    $ip = getenv("REMOTE_ADDR");
    }
    return $ip;
    }
    // ## LOG DOSYASI YAZALIM
    function logla($logmetin){
    $dosya = 'log.html';
    $metin = date('d-m-Y h:i - ').$logmetin.'<br/>';
    $fh = fopen($dosya, 'a+') or die('Hata!');
    fwrite($fh, $metin);
    fclose($fh);
    $_SESSION['ipadreskayit'] = true;
    }
    
    // ## ŞEHİR BİLGİSİNİ BULALIM
    if(!isset($_SESSION['ipadreskayit'])){
    function sehir_bul($ip){
    $default = 'Bilinmiyor';
    if (!is_string($ip) || strlen($ip) < 1 || $ip == '127.0.0.1' || $ip == 'localhost'){
    $ip = '8.8.8.8';
    }
    $curlopt_useragent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36';
    $url = 'http://www.ipsorgu.com/?ip=' . urlencode($ip) . '#sorgu';
    $ch = curl_init();
    $curl_opt = array(
    CURLOPT_FOLLOWLOCATION => 1,
    CURLOPT_HEADER => 0,
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_USERAGENT => $curlopt_useragent,
    CURLOPT_URL => $url,
    CURLOPT_TIMEOUT => 1,
    CURLOPT_REFERER => 'http://' . $_SERVER['HTTP_HOST'],
    );
    curl_setopt_array($ch, $curl_opt);
    $content = curl_exec($ch);
    curl_close($ch);
    
    if(preg_match('#<title>(.*?)</title>#', $content, $regs)){
    $city=$regs[1];
    }
    if($city != ''){
    $city=explode("-", $city);
    $city=trim($city[0]);
    logla($city);
    }else{
    return $default;
    }
    }
    sehir_bul(ipogrenme());
    }
    
    ?>
    iki farklı sitede denedim hocam aynı hatayı verdi. HTTP ERROR 500



    @php_bot; yardımcı olmuştur sorunu halletmiştir. Teşekkür ederim.
  • 09-01-2020, 16:45:46
    #6
    Kimlik doğrulama veya yönetimden onay bekliyor.
    php_bot adlı üyeden alıntı: mesajı görüntüle
    Bu şekilde denermisin birde suncuda denedim çalışıyor.
    <?php
    
    session_start();
    
    // ## KULLANICININ DOĞRU İP ADRESİNİ ÖĞRENELİM!
    function ipogrenme(){
    if(getenv("HTTP_CLIENT_IP")){
    $ip = getenv("HTTP_CLIENT_IP");
    }else if(getenv("HTTP_X_FORWARDED_FOR")){
    $ip = getenv("HTTP_X_FORWARDED_FOR");
    if(strstr($ip, ',')) {
    $tmp = explode (',', $ip);
    $ip = trim($tmp[0]);
    }
    }else{
    $ip = getenv("REMOTE_ADDR");
    }
    return $ip;
    }
    // ## LOG DOSYASI YAZALIM
    function logla($logmetin){
    $dosya = 'log.html';
    $metin = date('d-m-Y h:i - ').$logmetin.'<br/>';
    $fh = fopen($dosya, 'a+') or die('Hata!');
    fwrite($fh, $metin);
    fclose($fh);
    $_SESSION['ipadreskayit'] = true;
    }
    
    // ## ŞEHİR BİLGİSİNİ BULALIM
    if(!isset($_SESSION['ipadreskayit'])){
    function sehir_bul($ip){
    $default = 'Bilinmiyor';
    if (!is_string($ip) || strlen($ip) < 1 || $ip == '127.0.0.1' || $ip == 'localhost'){
    $ip = '8.8.8.8';
    }
    $curlopt_useragent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36';
    $url = 'http://www.ipsorgu.com/?ip=' . urlencode($ip) . '#sorgu';
    $ch = curl_init();
    $curl_opt = array(
    CURLOPT_FOLLOWLOCATION => 1,
    CURLOPT_HEADER => 0,
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_USERAGENT => $curlopt_useragent,
    CURLOPT_URL => $url,
    CURLOPT_TIMEOUT => 1,
    CURLOPT_REFERER => 'http://' . $_SERVER['HTTP_HOST'],
    );
    curl_setopt_array($ch, $curl_opt);
    $content = curl_exec($ch);
    curl_close($ch);
    
    if(preg_match('#<title>(.*?)</title>#', $content, $regs)){
    $city=$regs[1];
    }
    if($city != ''){
    $city=explode("-", $city);
    $city=trim($city[0]);
    logla($city);
    }else{
    return $default;
    }
    }
    sehir_bul(ipogrenme());
    }
    
    ?>
    Üstad merhaba bu kodu nereye yapıştıracağız acaba. Ben sitemde tek bir sayfaya girenlerin ip adreslerini toplamak istiyorum. İletişim sayfamda body kısmına yapıştırdım fakat olmadı. Sitem html tabanlı
  • 09-01-2020, 21:39:50
    #7
    karelservisinet adlı üyeden alıntı: mesajı görüntüle
    Üstad merhaba bu kodu nereye yapıştıracağız acaba. Ben sitemde tek bir sayfaya girenlerin ip adreslerini toplamak istiyorum. İletişim sayfamda body kısmına yapıştırdım fakat olmadı. Sitem html tabanlı
    maalesef bu kodları html sayfada kullanamazsınız
  • 09-01-2020, 21:42:21
    #8
    php_bot adlı üyeden alıntı: mesajı görüntüle
    maalesef bu kodları html sayfada kullanamazsınız
    hocam bu kodları scriptimde kullanmak istiyorum acaba bu mümkün müdür?
  • 09-01-2020, 21:48:15
    #9
    bunyaminbayindi adlı üyeden alıntı: mesajı görüntüle
    hocam bu kodları scriptimde kullanmak istiyorum acaba bu mümkün müdür?
    Kullanabilirsiniz tabii ki paylaşım forumundayız