• 04-10-2022, 00:00:50
    #1
    Merhaba,
    ASP ile yazılmış bir web sitesinde karşı tarafa login olmam gerekiyor.
    __VIEWSTATE değerini çekiyorum ama post edemiyorum...
    Yardımcı olabilecek kimse var mıdır?
  • 04-10-2022, 00:01:39
    #2
    cURL kodunuzu okunabilir şekilde paylaşır mısınız?
  • 04-10-2022, 00:06:02
    #3
    curl kodunuzu gönderin hocam
  • 04-10-2022, 00:07:38
    #4
    <?php
    
    $ch = curl_init();
    
    $params = [
        '__EVENTTARGET'       => '',
        '__EVENTARGUMENT'     => '',
        '__VIEWSTATE'         => $viewstate,
        '__VIEWSTATEGENERATOR'   => $viewgenerator,
        'ctl00$ContentPlaceHolder1$LoginControl1$txtUserName' => 'xx',
        'ctl00$ContentPlaceHolder1$LoginControl1$txtPassword' => 'xx',
        'ctl00$ContentPlaceHolder1$LoginControl1$LoginBtn' => '1',];
    
        curl_setopt($ch, CURLOPT_URL,'https://www.sunnyportal.com/Templates/Login.aspx');
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_REFERER, "https://www.sunnyportal.com/Templates/Login.aspx");
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0");
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
        curl_setopt($ch, CURLOPT_COOKIE, 'cookies.txt');
        curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies2.txt');
        $source = curl_exec($ch);
    
        preg_match('@<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value=\"(.*)\" />@', $source, $sonuc1);
        $viewstate = $sonuc1[1];
    
        preg_match('@<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value=\"(.*)\" />@', $source, $sonuc);
        $viewgenerator = $sonuc[1];
    
    
        curl_close($ch);
    
        echo $viewstate;
        echo "<br>";
        echo $viewgenerator;
        echo "<br>";
        echo $source;
        /*preg_match($regexViewstate, $source, $sonuc);*/
    ?>
  • 04-10-2022, 00:11:08
    #5
    POST isteği için istek türünü belirlemeniz gerekir.
    Aşağıdaki kodu kullanabilirsiniz.

    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  • 04-10-2022, 00:19:09
    #6
    profweb adlı üyeden alıntı: mesajı görüntüle
    POST isteği için istek türünü belirlemeniz gerekir.
    Aşağıdaki kodu kullanabilirsiniz.

    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    Ekledim hocam,

    $viewstate ve $viewgenerator değişkenlerine echo ile ekrana yazdırılan değeri atayıp post etmem mümkün mü?

    Aşağıdaki hatayı alıyorum ve login failed uyarısı veriyor.

    Warning: Undefined variable $viewstate in C:laragonwwwcurl.php on line 8
    Warning: Undefined variable $viewgenerator in C:laragonwwwcurl.php on line 9
  • 04-10-2022, 00:26:20
    #7
    tolgajan adlı üyeden alıntı: mesajı görüntüle
    Ekledim hocam,

    $viewstate ve $viewgenerator değişkenlerine echo ile ekrana yazdırılan değeri atayıp post etmem mümkün mü?

    Aşağıdaki hatayı alıyorum ve login failed uyarısı veriyor.

    Warning: Undefined variable $viewstate in C:laragonwwwcurl.php on line 8
    Warning: Undefined variable $viewgenerator in C:laragonwwwcurl.php on line 9
    Kullanımınız yanlış. Bunu tek istek ile yapamazsınız.
    Öncelikle VIEWSTATE ve diğer alanların olduğu sayfaya bir GET isteği göndererek kaynak kodu almalısınız.
    Daha sonra ayrıştırdığınız VIEWSTATE ve diğer değişkenleri POST isteği içerisinde kullanmanız gerekiyor.

    Ek olarak, COOKIE ve COOKIEJAR değişkenlerini aynı dosya olarak güncelleyiniz.
  • 04-10-2022, 00:42:56
    #8
    <?php
    $cookieFile = "cookies.txt";
    if(!file_exists($cookieFile)) {
        $fh = fopen($cookieFile, "w");
        fwrite($fh, "");
        fclose($fh);
    }
    $curl = curl_init();
    curl_setopt_array($curl, array(
      CURLOPT_URL => "https://www.sunnyportal.com/",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_FOLLOWLOCATION => true,
      CURLOPT_COOKIEJAR => 'cookies.txt',
      CURLOPT_COOKIEFILE => 'cookies.txt',
      CURLOPT_CUSTOMREQUEST => "GET"
    ));
    $response = curl_exec($curl);
    preg_match('@<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value=\"(.*)\" />@', $response, $sonuc1);
    $viewstate = $sonuc1[1];
    preg_match('@<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value=\"(.*)\" />@', $response, $sonuc);
    $viewgenerator = $sonuc[1];
    $ch = curl_init();
     
    $params = [
        '__EVENTTARGET' => '',
        '__EVENTARGUMENT' => '',
        '__VIEWSTATE' => $viewstate,
        '__VIEWSTATEGENERATOR' => $viewgenerator,
        'ctl00$ContentPlaceHolder1$LoginControl1$txtUserName' => 'asfasfaf@sdafasdf.com',
        'ctl00$ContentPlaceHolder1$LoginControl1$txtPassword' => 'asfasfs',
        'ctl00$ContentPlaceHolder1$LoginControl1$LoginBtn' => 'Oturum aç',
        'ctl00$ContentPlaceHolder1$LoginControl1$RedirectURL' => '',
        'ctl00$ContentPlaceHolder1$LoginControl1$RedirectPlant' => '',
        'ctl00$ContentPlaceHolder1$LoginControl1$RedirectPage' => '',
        'ctl00$ContentPlaceHolder1$LoginControl1$RedirectDevice' => '',
        'ctl00$ContentPlaceHolder1$LoginControl1$RedirectOther' => '',
        'ctl00$ContentPlaceHolder1$LoginControl1$PlantIdentifier' => '',
        'ctl00$ContentPlaceHolder1$LoginControl1$ServiceAccess' => 'true',
        'ClientScreenWidth' => '1366',
        'ClientScreenHeight' => '768',
        'ClientScreenAvailWidth' => '1366',
        'ClientScreenAvailHeight' => '728',
        'ClientWindowInnerWidth' => '1365',
        'ClientWindowInnerHeight' => '367',
        'ClientBrowserVersion' => '64',
        'ClientAppVersion' => '5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36',
        'ClientAppName' => 'Netscape',
        'ClientLanguage' => 'tr',
        'ClientPlatform' => 'Win32',
        'ClientUserAgent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36'
      ];
     
        curl_setopt($ch, CURLOPT_URL,'https://www.sunnyportal.com/Templates/Login.aspx');
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_REFERER, "https://www.sunnyportal.com/Templates/Login.aspx");
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0");
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
        curl_setopt($ch, CURLOPT_COOKIE, 'cookies.txt');
        curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
        $source = curl_exec($ch);
     
        curl_close($ch);
        echo $source;
        
    ?>
    al bakalım
  • 04-10-2022, 00:54:22
    #9
    doganemrex adlı üyeden alıntı: mesajı görüntüle
    <?php
    $cookieFile = "cookies.txt";
    if(!file_exists($cookieFile)) {
        $fh = fopen($cookieFile, "w");
        fwrite($fh, "");
        fclose($fh);
    }
    $curl = curl_init();
    curl_setopt_array($curl, array(
      CURLOPT_URL => "https://www.sunnyportal.com/",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_FOLLOWLOCATION => true,
      CURLOPT_COOKIEJAR => 'cookies.txt',
      CURLOPT_COOKIEFILE => 'cookies.txt',
      CURLOPT_CUSTOMREQUEST => "GET"
    ));
    $response = curl_exec($curl);
    preg_match('@<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value=\"(.*)\" />@', $response, $sonuc1);
    $viewstate = $sonuc1[1];
    preg_match('@<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value=\"(.*)\" />@', $response, $sonuc);
    $viewgenerator = $sonuc[1];
    $ch = curl_init();
     
    $params = [
        '__EVENTTARGET' => '',
        '__EVENTARGUMENT' => '',
        '__VIEWSTATE' => $viewstate,
        '__VIEWSTATEGENERATOR' => $viewgenerator,
        'ctl00$ContentPlaceHolder1$LoginControl1$txtUserName' => 'asfasfaf@sdafasdf.com',
        'ctl00$ContentPlaceHolder1$LoginControl1$txtPassword' => 'asfasfs',
        'ctl00$ContentPlaceHolder1$LoginControl1$LoginBtn' => 'Oturum aç',
        'ctl00$ContentPlaceHolder1$LoginControl1$RedirectURL' => '',
        'ctl00$ContentPlaceHolder1$LoginControl1$RedirectPlant' => '',
        'ctl00$ContentPlaceHolder1$LoginControl1$RedirectPage' => '',
        'ctl00$ContentPlaceHolder1$LoginControl1$RedirectDevice' => '',
        'ctl00$ContentPlaceHolder1$LoginControl1$RedirectOther' => '',
        'ctl00$ContentPlaceHolder1$LoginControl1$PlantIdentifier' => '',
        'ctl00$ContentPlaceHolder1$LoginControl1$ServiceAccess' => 'true',
        'ClientScreenWidth' => '1366',
        'ClientScreenHeight' => '768',
        'ClientScreenAvailWidth' => '1366',
        'ClientScreenAvailHeight' => '728',
        'ClientWindowInnerWidth' => '1365',
        'ClientWindowInnerHeight' => '367',
        'ClientBrowserVersion' => '64',
        'ClientAppVersion' => '5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36',
        'ClientAppName' => 'Netscape',
        'ClientLanguage' => 'tr',
        'ClientPlatform' => 'Win32',
        'ClientUserAgent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36'
      ];
     
        curl_setopt($ch, CURLOPT_URL,'https://www.sunnyportal.com/Templates/Login.aspx');
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_REFERER, "https://www.sunnyportal.com/Templates/Login.aspx");
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0");
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
        curl_setopt($ch, CURLOPT_COOKIE, 'cookies.txt');
        curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
        $source = curl_exec($ch);
     
        curl_close($ch);
        echo $source;
        
    ?>
    al bakalım
    Hocam çok teşekkür ederim. Emeğinize sağlık..
    Fakat kaynak kodunda baktığımda get ile gelen __VIEWSTATE verisi ile yüklenen __VIEWSTATE verisi farklı yine login failed hatasına düşüyor..