Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*$url = "http://localhost:8080/Default.aspx";
- $ckfile = tempnam("/tmp", "CURLCOOKIE");
- $useragent = 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/5.0.342.3 Safari/533.2';
- $username = "gianrachmat@gmail.com";
- $password = "st21it1p0";
- $f = fopen('log.txt', 'w'); // file to write request header for debug purpose
- /**
- Get __VIEWSTATE & __EVENTVALIDATION
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
- $html = curl_exec($ch);
- curl_close($ch);
- preg_match('~<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="(.*?)" />~', $html, $viewstate);
- preg_match('~<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="(.*?)" />~', $html, $eventValidation);
- $viewstate = $viewstate[1];
- $eventValidation = $eventValidation[1];
- /**
- Start Login process
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
- curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
- curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);
- curl_setopt($ch, CURLOPT_HEADER, FALSE);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($ch, CURLOPT_REFERER, $url);
- curl_setopt($ch, CURLOPT_VERBOSE, 1);
- curl_setopt($ch, CURLOPT_STDERR, $f);
- curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
- // Collecting all POST fields
- $postfields = array();
- $postfields['__EVENTTARGET'] = "";
- $postfields['__EVENTARGUMENT'] = "";
- $postfields['__VIEWSTATE'] = $viewstate;
- $postfields['__EVENTVALIDATION'] = $eventValidation;
- $postfields['ctl00$ctl00$ucMarketPlaceSupportNavigation$txtMPTopSignInEmail'] = $username;
- $postfields['ctl00$ctl00$ucMarketPlaceSupportNavigation$txtMPTopSignInPasswordTextNormal'] = "Password";
- $postfields['ctl00$ctl00$ucMarketPlaceSupportNavigation$txtMPTopSignInPassword'] = $password;
- $postfields['ctl00$ctl00$ucMarketPlaceSupportNavigation$btnSigninTop'] = 'Sign in';
- $postfields['ctl00$ctl00$cplhMain$cplhContent$txtEmail'] = 'Email address';
- $postfields['ctl00$ctl00$cplhMain$cplhContent$rdlPasswordYes'] = 'Password';
- $postfields['ctl00$ctl00$cplhMain$cplhContent$txtPassword'] = '';
- $postfields['ctl00$ctl00$cplhMain$cplhContent$hdnEmailDefault'] = 'Email address';
- $postfields['ctl00$ctl00$cplhMain$cplhContent$hdnPasswordDefault'] = 'Password';
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
- $ret = curl_exec($ch); // Get result after login page.
- print $ret;*/
- function get_headers_from_curl_response($headerContent)
- {
- $headers = array();
- // Split the string on every "double" new line.
- $arrRequests = explode("\r\n\r\n", $headerContent);
- // Loop of response headers. The "count() -1" is to
- //avoid an empty row for the extra line break before the body of the response.
- for ($index = 0; $index < count($arrRequests) -1; $index++) {
- foreach (explode("\r\n", $arrRequests[$index]) as $i => $line)
- {
- if ($i === 0)
- $headers[$index]['http_code'] = $line;
- else
- {
- list ($key, $value) = explode(': ', $line);
- $headers[$index][$key] = $value;
- }
- }
- }
- return $headers;
- }
- function regexExtract($text, $regex, $regs, $nthValue)
- {
- if (preg_match($regex, $text, $regs)) {
- $result = $regs[$nthValue];
- }
- else {
- $result = "";
- }
- return $result;
- }
- $regexViewstate = '/__VIEWSTATE\" value=\"(.*)\"/i';
- $regexEventVal = '/__EVENTVALIDATION\" value=\"(.*)\"/i';
- $ch = curl_init("http://localhost:8080/Default.aspx");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_HEADER, 1);
- curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
- $response = curl_exec($ch);
- curl_close($ch);
- $viewstate = regexExtract($response,$regexViewstate,$regs,1);
- $eventval = regexExtract($response, $regexEventVal,$regs,1);
- $params = array(
- '__EVENTTARGET' => '',
- '__EVENTARGUMENT' => '',
- '__VIEWSTATE' => $viewstate,
- '__EVENTVALIDATION' => $eventval,
- 'ctl00$txtUsername' => 'gianrachmat@gmail.com',
- 'ctl00$txtPassword' => 'st21it1p0',
- 'ctl00$ImgLogin.x' => '0',
- 'ctl00$ImgLogin.y' => '0',
- );
- $ch2 = curl_init("http://localhost:8080/Default.aspx");
- curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch2, CURLOPT_HEADER, 1);
- curl_setopt ($ch2, CURLOPT_POST, true);
- curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch2, CURLOPT_POSTFIELDS, http_build_query($params));
- curl_setopt ($ch2, CURLOPT_COOKIE,'cookies.txt');
- curl_setopt($ch2,CURLOPT_COOKIEJAR,'cookies2.txt');
- $response2 = curl_exec($ch2);
- curl_close($ch2);
- foreach(get_headers_from_curl_response($response2) as $value)
- {
- foreach($value as $key => $value2)
- {
- echo $key . ": " .$value2 . "<br />";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement