• 22-07-2010, 15:59:02
    #1
    Curl ile ilgili çalışıyorum. Bir yerlerde hata yapıyorum ama anlyamadım. Yardıma ihtiyacım var. Joomla tabanlı bir siteye uye girşi yapmaya çalışıyorum.

    curlgiris.php ile ilk bağlantı:
    $uname = "kullanıcıadı";
    $pass = "şifre";
    $ch = curl_init();
    $cookie_new = fopen ("cookie.txt", "w");
    curl_setopt($ch, CURLOPT_URL, "http://www.siteadi.com/index.php?option=com_user&task=login");
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS,"username=".$uname."&passwd=".$pass);
    curl_setopt ($ch, CURLOPT_WRITEHEADER, $cookie_new);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    $icerik = curl_exec($ch);
    echo $icerik;
    fclose ($cookie_new);
    curl_close($ch);
    Bu sayfa giriş yapıldığında normalde index.php ye yönlendirdiği için bi tane index.php hazırladım.

    index.php
    echo '<meta http-equiv="refresh" content="0; url=curlson.php?session='.$_GET['session'].'"/>';
    Bunuda curlson.php ye gönderdim.
    $session =$_GET['session'];
    $dosya = fopen('cookie.txt','r');
    $icerik = fread($dosya, filesize('cookie.txt'));
    $dizi = (explode("Set-Cookie: ",$icerik));
    $session1=(explode(";",$dizi[1]));
    $session1['0'] = trim($session1['0']);
    $session2=(explode(";",$dizi[2]));
    $session2['0'] = trim($session2['0']);
    $session3=(explode(";",$dizi[3]));
    $session3['0'] = trim($session3['0']);
    $cookie = $session2['0']."; ".$session3['0']."; ".$session1['0'];
    
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://www.siteadi.com/index.php?option=com_user");
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch,CURLOPT_COOKIE,$cookie);
    $sayfaicerik= curl_exec($ch);
    
    curl_close($ch);
    Yanlız bu son curlson.php deki amacım index.php den yeni sayfaya yönlenmek. Ama $session değişkenini kullanamadım. Onu nasıl kullanmam gerektiğini bilmiyorum.

    cookie.txt adlı dosya çerezleri kaydediyor. ama ben bu çerezleri nasıl kullanmam gerektiğini anlayamadım. Çerezleri kullanamadığım için mi login olamıyorum yoksa başka bir durum mu var?


    Bunları başka bir yerden bakarak yaptım. Baya birşey öğrendim ama şu an tıkanmış durumdayım. Bir türlü düşündüğüm olmuyor. Siteye login olamıyorum.

    Yardımınıza ihtiyacım var.

    Not: Bu çalışmayı şu konudaki çalışmadan yararlanarak yapmaya çalışıyorum.
  • 22-07-2010, 16:23:57
    #2
    CURLOPT_COOKIEJAR
    CURLOPT_COOKIEFILE
    bu kodları incele cookieyei tekrar kullanacaksan CURLOPT_COOKIEFILE bu işini görecektir..
  • 22-07-2010, 17:00:58
    #3
    Üyeliği durduruldu
    class cURL {
    var $headers;
    var $user_agent;
    var $compression;
    var $cookie_file;
    var $proxy;
    function cURL($cookies=TRUE,$cookie='cookie.txt',$compression='gzip',$proxy='') {
    $this->headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg';
    $this->headers[] = 'Connection: Keep-Alive';
    $this->headers[] = 'Content-type: application/x-www-form-urlencoded;charset=utf-8';
    $this->user_agent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)';
    $this->compression=$compression;
    $this->proxy=$proxy;
    $this->cookies=$cookies;
    if ($this->cookies == TRUE) $this->cookie($cookie);
    }
    function cookie($cookie_file) {
    if (file_exists($cookie_file)) {
    $this->cookie_file=$cookie_file;
    } else {
    fopen($cookie_file,'w') or $this->error('Cookie yaratılamadı. İşlem gerçekleşmemiş olabilir..');
    $this->cookie_file=$cookie_file;
    fclose($this->cookie_file);
    }
    }
    function get($url) {
    $process = curl_init($url);
    curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers);
    curl_setopt($process, CURLOPT_HEADER, 1);
    curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent);
    if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEFILE, $this->cookie_file);
    if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEJAR, $this->cookie_file);
    curl_setopt($process,CURLOPT_ENCODING , $this->compression);
    curl_setopt($process, CURLOPT_TIMEOUT, 30);
    if ($this->proxy) curl_setopt($process, CURLOPT_PROXY, $this->proxy);
    curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
    $return = curl_exec($process);
    curl_close($process);
    // burada sonuçlar dönecek
    echo $return;
    }
    function post($url,$data) {
    $process = curl_init($url);
    curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers);
    curl_setopt($process, CURLOPT_HEADER, 1);
    curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent);
    if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEFILE, $this->cookie_file);
    if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEJAR, $this->cookie_file);
    curl_setopt($process, CURLOPT_ENCODING , $this->compression);
    curl_setopt($process, CURLOPT_TIMEOUT, 30);
    if ($this->proxy) curl_setopt($process, CURLOPT_PROXY, $this->proxy);
    curl_setopt($process, CURLOPT_POSTFIELDS, $data);
    curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($process, CURLOPT_POST, 1);
    $return = curl_exec($process);
    curl_close($process);
    return $return;
    }
    function error($error) {
    echo "<center><div style=\"width:500px;border: 3px solid #FFEEFF; padding: 3px; background-color: #FFDDFF;font-family: verdana; font-size: 10px\"><b>Hata:</b><br>$error</div></center>";
    die;
    }
    }
    sınıfları şu şekilde kullanabilirsin;

    $uname='Kullanıcı';
    $pass='Şifre';
    
    $cc=new cURL();
    $cc->post('http://www.siteadi.com/index.php?option=com_user','username='.$uname.'&passwd='.$pass.'');
    sayfaya veri göndermeyecek isen
    $cc->get('http://www.siteadi.com/index.php');
  • 22-07-2010, 18:53:03
    #4
    İkinizede teşekkür ederim. Keops kodları deneyeceğim. sayfaya veri göndereceğim. bu durumda nasıl olacak son bölüm?
  • 22-07-2010, 19:05:51
    #5
    ooaykac adlı üyeden alıntı: mesajı görüntüle
    İkinizede teşekkür ederim. Keops kodları deneyeceğim. sayfaya veri göndereceğim. bu durumda nasıl olacak son bölüm?

    sınıfı test etmedim veri göndereceksen böyle diyor
    $uname='Kullanıcı';
    $pass='Şifre';
    
    $cc=new cURL();
    $cc->post('http://www.siteadi.com/index.php?option=com_user','username='.$uname.'&passwd='.$pass.'');
  • 23-07-2010, 01:11:39
    #6
    Üyeliği durduruldu
    sınıfları şu şekilde kullanabilirsin yazısının altında belirttiğim gibi gönderebilirsin veriyi.
  • 23-07-2010, 16:44:09
    #7
    Arkadaşlar ilginiz için teşekkür ederim. Ama bana zor geldi o kodlar. Ben de ordan burdan bakarak oluştırdum kodları.

    Şu şekilde:
    $uname = "kullanıcı";
    $pass = "şifre";
    
    $ch = curl_init();
    $cookie_new = fopen ("cookie.txt", "w");
    curl_setopt($ch, CURLOPT_URL, "http://www.siteadi.com/index.php?option=com_user&task=login");
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS,"username=".$uname."&passwd=".$pass);
    curl_setopt ($ch, CURLOPT_WRITEHEADER, $cookie_new);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
    $icerik = curl_exec($ch);
    
    	$ch = curl_init();
    	$cookie = fopen ("cookie.txt", "r");
    	curl_setopt($ch, CURLOPT_URL, "http://www.siteadi.com/index.php?option=com_comprofiler&listid=12&task=usersList");
    	curl_setopt($ch, CURLOPT_HEADER, 1);
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    	curl_setopt($ch,CURLOPT_COOKIE,$cookie);
    	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
    	$sayfa = curl_exec($ch);
    
    
    	preg_match("/<title>(.*?)<\/title>/",$sayfa,$title);
        echo $title[1]; 
    
    
    fclose ($cookie_new); 
    curl_close($ch);
    Ama sorunlu. 1. sayfaya giriyor ve login oluyor sanırım. Çünkü ancak login olunca ana sayfaya yonlendiriyor. Yonlendirmeyi FOLLOWLOCATION ile alıp ordan da sadece uye bolumune açık bir sayfaya gonderiyorum. Ama Ama orada uye girişi yapmamış gibi görünüyor. Okuttuğum başlık uye girişi yapılmamış sayfanın başlığı. Yani cookie ile ilgili sorun var sanırım.


    Nerde hata yapıyorum sizce?
  • 23-07-2010, 16:46:52
    #8
    sana diyorumki hocam CURLOPT_COOKIEFILE fonksiyonunu kullan istediğin sayfaya gir :S anlatamıyorum galiba
    CURLOPT_COOKIEJAR cokie dosyası oluşturur CURLOPT_COOKIEFILE bu ise olşuturulan dosyayı kullanır :S olay bundan ibaret bunun bir sürü örmneğini verdim
    https://www.r10.net/1061523430-post21.html
    https://www.r10.net/php/687313-curl-i...pal-login.html
    http://www.phpogreniyorum.com/Php-De...iyonu-ile.html

    sen neyapmışssın fopen ile cokie acıyorsun :S CURLOPT_COOKIEFILE bunu kullan başın ağrımasın
  • 23-07-2010, 16:59:46
    #9
    ByTriSLaSiS adlı üyeden alıntı: mesajı görüntüle
    sana diyorumki hocam CURLOPT_COOKIEFILE fonksiyonunu kullan istediğin sayfaya gir :S anlatamıyorum galiba
    CURLOPT_COOKIEJAR cokie dosyası oluşturur CURLOPT_COOKIEFILE bu ise olşuturulan dosyayı kullanır :S olay bundan ibaret bunun bir sürü örmneğini verdim
    https://www.r10.net/1061523430-post21.html
    https://www.r10.net/php/687313-curl-i...pal-login.html
    http://www.phpogreniyorum.com/Php-De...iyonu-ile.html

    sen neyapmışssın fopen ile cokie acıyorsun :S CURLOPT_COOKIEFILE bunu kullan başın ağrımasın

    ok hocam. dur, kızma yapıyorum