jkkenzie Posted March 19, 2013 Share Posted March 19, 2013 Am trying to auto login at http://track.aasoftwares.net/pages/Premium_Tracking.htm am trying the following cURL but i get no results: <?php //initiate curl process $ch = curl_init(); $url = "http://track.futuresystems.co.ke/"; //set options /* There are a number of options, which you can use to manipulate the behaviour of this ''invisible browser''. See php.net/curl for more details. */ curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/My Test Browser"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); // ENABLE HTTP POST curl_setopt ($ch, CURLOPT_POST, 1); // SET POST PARAMETERS : FORM VALUES FOR EACH FIELD curl_setopt ($ch, CURLOPT_POSTFIELDS, 'txtUserName3=******&txtPassword3=*****'); //run the process and fetch the document $doc = curl_exec($ch); //terminate curl process curl_close($ch); //print output echo $doc; ?> any help! Quote Link to comment https://forums.phpfreaks.com/topic/275886-curl-automatic-login/ Share on other sites More sharing options...
monkeypaw201 Posted March 20, 2013 Share Posted March 20, 2013 Hi jkkenzie, Looking at the source code, there appear to be some hidden input fields that are being sent. Primarily a "__VIEWSTATE", which I would assume is some sort of session/temporary key to try to prevent what you are trying to do. However, never fear! There is a solution Here is some revised code. I've tested it and instead of giving me a login box it gives me an internal server error. Try it with actual credentials and let us know what happens. <?php //initiate curl process $ch = curl_init(); $url = "http://track.futuresystems.co.ke/"; //set options /* There are a number of options, which you can use to manipulate the behaviour of this ''invisible browser''. See php.net/curl for more details. */ curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/My Test Browser"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); //run the process and fetch the document $doc = curl_exec($ch); // extract viewstate input field $viewstate = explode('<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="',$doc); $viewstate = explode('" />',$viewstate[1]); $viewstate = $viewstate[0]; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/My Test Browser"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); // ENABLE HTTP POST curl_setopt ($ch, CURLOPT_POST, 1); // SET POST PARAMETERS : FORM VALUES FOR EACH FIELD curl_setopt ($ch, CURLOPT_POSTFIELDS, 'txtUserName3=******&txtPassword3=*****&__VIEWSTATE='.$viewstate); //run the process and fetch the document $doc = curl_exec($ch); //terminate curl process curl_close($ch); //print output echo $doc; ?> Quote Link to comment https://forums.phpfreaks.com/topic/275886-curl-automatic-login/#findComment-1419735 Share on other sites More sharing options...
Jimmie89 Posted May 21, 2013 Share Posted May 21, 2013 Hi monkeypaw201! I have a similar issue, except I log into a secure site. I've got this part working by using the following: $url = "https://www.fragrancex.com/customeraccount/customer_center.html"; $cr = curl_init($url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "fragrancex-chain.crt"); $curl_ret = curl_exec($cr); curl_close($cr); //run the process and fetch the document $doc = curl_exec($ch); //print output echo $doc; however, now I need to pass a value $__RequestVerificationToken back to the page and submit to login. I've borrowed your example above and tried a couple things, but it won't login. Would you kindly assist? Here's the full code: <?php $url = "https://www.fragrancex.com/customeraccount/customer_center.html"; $cr = curl_init($url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "fragrancex-chain.crt"); $curl_ret = curl_exec($cr); curl_close($cr); //run the process and fetch the document $doc = curl_exec($ch); // extract __RequestVerificationToken input field $__RequestVerificationToken = explode('<input name="__RequestVerificationToken" type="hidden" value="',$doc); $__RequestVerificationToken = explode('" />',$__RequestVerificationToken[1]); $__RequestVerificationToken = $__RequestVerificationToken[0]; curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "fragrancex-chain.crt"); // ENABLE HTTP POST curl_setopt ($ch, CURLOPT_POST, 1); // SET POST PARAMETERS : FORM VALUES FOR EACH FIELD curl_setopt ($ch, CURLOPT_POSTFIELDS, '__RequestVerificationToken='.$__RequestVerificationToken.'&UserName=somewhere%40over.the.rainbow&NewUser=False&Password=12345&action=Sign+in+using+our+secure+server&ReturnUrl='); //run the process and fetch the document $doc = curl_exec($ch); //terminate curl process curl_close($ch); //print output echo $doc; ?> Thanks in advance! J Quote Link to comment https://forums.phpfreaks.com/topic/275886-curl-automatic-login/#findComment-1431292 Share on other sites More sharing options...
fred666 Posted October 17, 2013 Share Posted October 17, 2013 hello Jimmie89 I have a similar issue for fragrancex login... Found you the solution? Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/275886-curl-automatic-login/#findComment-1454241 Share on other sites More sharing options...
fred666 Posted October 17, 2013 Share Posted October 17, 2013 hello Jimmie89 I have a similar issue for fragrancex login... Found you the solution? Thanks in advance! Hi monkeypaw201! I have a similar issue, except I log into a secure site. I've got this part working by using the following: $url = "https://www.fragrancex.com/customeraccount/customer_center.html"; $cr = curl_init($url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "fragrancex-chain.crt"); $curl_ret = curl_exec($cr); curl_close($cr); //run the process and fetch the document $doc = curl_exec($ch); //print output echo $doc; however, now I need to pass a value $__RequestVerificationToken back to the page and submit to login. I've borrowed your example above and tried a couple things, but it won't login. Would you kindly assist? Here's the full code: <?php $url = "https://www.fragrancex.com/customeraccount/customer_center.html"; $cr = curl_init($url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "fragrancex-chain.crt"); $curl_ret = curl_exec($cr); curl_close($cr); //run the process and fetch the document $doc = curl_exec($ch); // extract __RequestVerificationToken input field $__RequestVerificationToken = explode('<input name="__RequestVerificationToken" type="hidden" value="',$doc); $__RequestVerificationToken = explode('" />',$__RequestVerificationToken[1]); $__RequestVerificationToken = $__RequestVerificationToken[0]; curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "fragrancex-chain.crt"); // ENABLE HTTP POST curl_setopt ($ch, CURLOPT_POST, 1); // SET POST PARAMETERS : FORM VALUES FOR EACH FIELD curl_setopt ($ch, CURLOPT_POSTFIELDS, '__RequestVerificationToken='.$__RequestVerificationToken.'&UserName=somewhere%40over.the.rainbow&NewUser=False&Password=12345&action=Sign+in+using+our+secure+server&ReturnUrl='); //run the process and fetch the document $doc = curl_exec($ch); //terminate curl process curl_close($ch); //print output echo $doc; ?> Thanks in advance! J Quote Link to comment https://forums.phpfreaks.com/topic/275886-curl-automatic-login/#findComment-1454242 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.