how to login through php curl which is submited by javascript i.e no submit button in form -



how to login through php curl which is submited by javascript i.e no submit button in form -

i trying login secure https website thorugh curl . code running other sites website form submitting through javascript not working . using next code curl

<? # define target page $target = "https://www.domainname.com/login.jsf"; # define login form info $form_data="enter=enter&username=webbot&password=sp1der3"; # create curl session $ch = curl_init(); curl_setopt($ch, curlopt_url, $target); // define target site curl_setopt($ch, curlopt_returntransfer, true); // homecoming page in string curl_setopt($ch, curlopt_cookiejar, "cookies.txt"); // tell curl write cookies curl_setopt($ch, curlopt_cookiefile, "cookies.txt"); // tell curl cookies send curl_setopt($ch, curlopt_post, true); curl_setopt($ch, curlopt_postfields, $form_data); curl_setopt($ch, curlopt_followlocation, true); // follow redirects # execute php/curl session , echo downloaded page $page = curl_exec($ch); echo $page; # close curl session curl_close($ch); ?>

and login follows

<form name="login" method="post" action="./servelet" > username=<input type="text" name="username" value="" > password=<input type="text" name="password" value="" > <a href="javascript:void(0);" onclick="return submitfrm();">submit</a> <form>

please help solve issue . how login these type of forms. in advance. code working other login form submit submit button.

$email = ''; $password = '!'; $cookie_file_path = "/tmp/cookies.txt"; $loginurl = "/login.jsf"; $agent = "mozilla/4.0 (compatible; msie 6.0; windows nt 5.1"; // begin script $ch = curl_init(); // headers $headers[] = "accept: */*"; $headers[] = "connection: keep-alive"; // basic curl options requests curl_setopt($ch, curlopt_httpheader, $headers); curl_setopt($ch, curlopt_header, 0); curl_setopt($ch, curlopt_ssl_verifyhost, 0); curl_setopt($ch, curlopt_ssl_verifypeer, false); curl_setopt($ch, curlopt_useragent, $agent); curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_followlocation, 1); curl_setopt($ch, curlopt_cookiefile, $cookie_file_path); curl_setopt($ch, curlopt_cookiejar, $cookie_file_path); // set first url curl_setopt($ch, curlopt_url, $loginurl); // execute session cookies , required form inputs $content = curl_exec($ch); // grab hidden inputs form required login $fields = getformfields($content); $fields['loginform:username'] = $email; $fields['loginform:password'] = $password; // x value used in login url $x = ''; if (preg_match('/login\.jsf/i', $content, $match)) { echo $x = $match[1]; } //$loginurl = "https://cart2.barnesandnoble.com/mobileacct/op.asp?stage=signin"; $loginurl = "/pages/login.jsf"; // set postfields using extracted form $postfields = http_build_query($fields); // alter url login url curl_setopt($ch, curlopt_url, $loginurl); // set post options curl_setopt($ch, curlopt_post, 1); curl_setopt($ch, curlopt_postfields, $postfields); // perform login $result = curl_exec($ch); //print $result; $url2=''; curl_setopt($ch, curlopt_url, $url2); $result2 = curl_exec($ch); function getformfields($data) { if (preg_match('/(<form id="loginform.*?<\/form>)/is', $data, $matches)) { $inputs = getinputs($matches[1]); homecoming $inputs; } else { die('didnt find login form'); } }

javascript curl web-scraping screen-scraping scrape

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -