• 26-03-2015, 23:35:59
    #1
    Merhaba arkadaşlar curl ile post giriş yapıp veri cekimi yapıyor fakat bazı sunucularda followlocation safe mod ve openbasedir e takıldıgı için calısmıyor bu fonksiyon. onun için internette bir fonksiyon buldum denedim fakat giriş yapıp gerekli sayfaya yönlenemedim.
    Denedigim fonk.
    function curl_exec_follow(/*resource*/ $ch, /*int*/ &$maxredirect = null) {
        $mr = $maxredirect === null ? 2 : intval($maxredirect);
        if (ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')) {
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $mr > 0);
            curl_setopt($ch, CURLOPT_MAXREDIRS, $mr);
        } else {
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
            if ($mr > 0) {
                $newurl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
    
                $rch = curl_copy_handle($ch);
                curl_setopt($rch, CURLOPT_HEADER, true);
                curl_setopt($rch, CURLOPT_NOBODY, true);
                curl_setopt($rch, CURLOPT_FORBID_REUSE, false);
                curl_setopt($rch, CURLOPT_RETURNTRANSFER, true);
                do {
                    curl_setopt($rch, CURLOPT_URL, $newurl);
                    $header = curl_exec($rch);
                    if (curl_errno($rch)) {
                        $code = 0;
                    } else {
                        $code = curl_getinfo($rch, CURLINFO_HTTP_CODE);
                        if ($code == 301 || $code == 302) {
                            preg_match('/Location:(.*?)\n/', $header, $matches);
                            $newurl = trim(array_pop($matches));
                        } else {
                            $code = 0;
                        }
                    }
                } while ($code && --$mr);
                curl_close($rch);
                if (!$mr) {
                    if ($maxredirect === null) {
                        trigger_error('Too many redirects. When following redirects, libcurl hit the maximum amount.', E_USER_WARNING);
                    } else {
                        $maxredirect = 0;
                    }
                    return false;
                }
                curl_setopt($ch, CURLOPT_URL, $newurl);
            }
        }
        return curl_exec($ch);
    }
    kendi curl fonksiyonum.
    function curla(){
    $ch = curl_init();
    //curl_setopt($ch, CURLOPT_HEADER, false);
    //curl_setopt($ch, CURLOPT_NOBODY, false);
    curl_setopt($ch, CURLOPT_URL, 'http://www.site.com/');
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
    curl_setopt($ch, CURLOPT_COOKIE, "cookiename=0");
    //curl_setopt($ch, CURLOPT_USERAGENT,"Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'username=cankurt51%40gmail.com&password=1234567%2F*-&sub_login=Account+Login');
    $store = curl_exec_follow($ch);
    curl_close($ch);
    return $store;
    }
    curl_setopt() [<a href='function.curl-setopt'>function.curl-setopt</a>]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /home2/sss/public_html/settings.php on line 341
    Line 341:
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $mr > 0);
  • 27-03-2015, 21:05:04
    #2
    arkadaşlar yok mu bu konuda yardımcı olabilecek kimse?
  • 28-03-2015, 00:31:17
    #3
    Malesef en iyi çözüm bu konuda curl sürümü yükseltmek bir kaç bu durum için türetilmeye çalışıl function var yabancı kaynaklarda fakat ondalardada followlocationdan kacacaz derken başka yerden yine yasak yiyorlar.
  • 28-03-2015, 01:53:57
    #4
    @ufukt51; rmccue/requests paketini kullanabilirsin. Oturum işlemi yapmak için Requests_Session sınıfını kullanabilirsin. Çerezlerle ilgili işlemler için Requests_Hooks sınıfı oluşturun. Atlayabileceğiniz (hooklayabileceğin) yerler dokümantasyonda yazıyor. curl.before_send işini görecektir. Söylediğim kısma atlayıp orada çerezlerle ilgili opsiyonları yapabilirsin. Bu paket ile yaşamakta olduğun sorunu çözmüş olacaksın.
  • 29-03-2015, 01:30:57
    #5
    Kimlik doğrulama veya yönetimden onay bekliyor.
    ufukt51 adlı üyeden alıntı: mesajı görüntüle
    Merhaba arkadaşlar curl ile post giriş yapıp veri cekimi yapıyor fakat bazı sunucularda followlocation safe mod ve openbasedir e takıldıgı için calısmıyor bu fonksiyon. onun için internette bir fonksiyon buldum denedim fakat giriş yapıp gerekli sayfaya yönlenemedim.
    Denedigim fonk.
    Hocam oturum açtığınız site cookie mi sessionmu kullanıyor bilmiyorum fakat session için follow location kullanmadan şu şekilde veri çekebildim.

    s1.php:
    <?php
    $a=curl_init();
    curl_setopt($a,CURLOPT_URL,"http://sitem.com/s2.php");
    curl_setopt($a,CURLOPT_USERAGENT,"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");
    curl_setopt($a,CURLOPT_REFERER,"http://google.com.tr");
    curl_setopt($a,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($a,CURLOPT_HEADER,true);
    $b=curl_exec($a);
    preg_match('#Location:(.*?)\n#si',$b,$c);
    preg_match('#PHPSESSID=(.*?);#si',$b,$c1);
    $uri="http://sitem.com/".str_replace(array("\n","\r","\t"," "),'',$c[1]);
    $headers = array();
    $headers[] = 'Host: sitem.com';
    $headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0';
    $headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
    $headers[] = 'Accept-Language: tr-TR,tr;q=0.8,en-US;q=0.5,en;q=0.3';
    $headers[] = 'Cookie: PHPSESSID='.$c1[1].';';
    $headers[] = 'Connection: keep-alive';
    curl_setopt($a,CURLOPT_HEADER,false);
    curl_setopt($a,CURLOPT_HTTPHEADER,$headers);
    curl_setopt($a,CURLOPT_URL,$uri);
    $d=curl_exec($a);
    curl_close($a);
    echo $d;
    ?>
    s2.php:
    <?php
    ob_start();
    session_start();
    $_SESSION['deneme']="deneme".rand(1000,9000);
    header("Location:s3.php");
    ob_end_flush();
    ?>
    s3.php:
    <?php
    ob_start();
    session_start();
    if($_SESSION['deneme']) {
    	echo $_SESSION['deneme'];
    }
    ob_end_flush();
    ?>

    Çıktı: deneme7942

    Hocam eğer anlamadıysanız olayı derinlemesine açıklayabilirim.
  • 29-03-2015, 18:38:46
    #6
    teşekkür ederim sorun çözüldü. kapatılabilir.