<?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);*/
?>