daydreamer Posted March 4, 2008 Share Posted March 4, 2008 I am trying to use curl to submit a form on web server using https. I have a php file with the code, and an html file on my server, which is a clone of the form I am trying to post to. When I manually fill out my html form, and click "Continue", it forwards all the fields I have entered to the https server page. I am trying to get my php script to fill out and click continue for me so I can automatically fill out the forms. MY html form, (clone of form I am posting to, which is on https://registration.co.uk/Registration/Create) <form name="f" method="post" action="https://registration.co.uk/Registration/Create"> <input type="hidden" name="in_portalPreference" id="" value="P" size="24" maxLength="2" /> <input type="hidden" name="IAF_domainName" id="" value=" " size="24" maxLength="15" /> <input type="hidden" name="PAF_VALIDATED_ADDRESS" id="" value="false" size="24" maxLength="15" /> <input type="hidden" name="page_name" id="" value="../Registration/Create" size="24" maxLength="25" /> Forename: <input type="text" name="in_forename" id="in_forename" value="" size="15" maxLength="15" /> Lastname: <input type="text" name="in_lastname" id="in_lastname" value="" size="15" maxLength="15" /> //lots of other fields here (similar to the name fields) <input type="submit" id="submit" name="submit" value="Continue" title="Done" /> PHP code <?php $curl = curl_init(); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_COOKIEFILE, "cookiefile123"); curl_setopt($curl, CURLOPT_COOKIEJAR, "cookiefile123"); # SAME cookiefile curl_setopt($curl, CURLOPT_URL, "localhost/register.html"); curl_setopt($curl, CURLOPT_POSTFIELDS, "in_lastname=Mubs&in_forename=John&submit=Continue"); curl_exec($curl); // execute above and send it to my form curl_setopt($curl, CURLOPT_URL, "https://registration.co.uk/Registration/Create"); // execute 'action' my html form, posting details to $xxx = curl_exec($curl); // this page. echo $xxx; curl_close ($curl); ?> When I manually fill out my html form and click continue in my browser, it forwards the fields to https://registration.co.uk/Registration/Create with no problem. When I run my php file, the server I am posting to says that an error has occurred, but does not specify why. I think it is because my php code is not spoofing a browser good enough, and the server knows that is is a script so it rejects the request. My questions are: A) Is my script spoofing a browser correctly, and are the settings correct. B) Are the settings correct for posting to https forms? C) What else should/shouldent I be doing!? Thanks for the help. Quote Link to comment Share on other sites More sharing options...
daydreamer Posted March 4, 2008 Author Share Posted March 4, 2008 Anyone? Quote Link to comment Share on other sites More sharing options...
daydreamer Posted March 4, 2008 Author Share Posted March 4, 2008 Anybody at all? Quote Link to comment Share on other sites More sharing options...
daydreamer Posted March 5, 2008 Author Share Posted March 5, 2008 When your finished writing up your answer drafts, just post em in your own time, theirs no hurry! Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted March 5, 2008 Share Posted March 5, 2008 try this: <?php if(!isset($_POST['submit'])){ // echo your form ?> <form name="f" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input type="hidden" name="in_portalPreference" id="" value="P" size="24" maxLength="2" /> <input type="hidden" name="IAF_domainName" id="" value=" " size="24" maxLength="15" /> <input type="hidden" name="PAF_VALIDATED_ADDRESS" id="" value="false" size="24" maxLength="15" /> <input type="hidden" name="page_name" id="" value="../Registration/Create" size="24" maxLength="25" /> Forename: <input type="text" name="in_forename" id="in_forename" value="" size="15" maxLength="15" /> Lastname: <input type="text" name="in_lastname" id="in_lastname" value="" size="15" maxLength="15" /> //lots of other fields here (similar to the name fields) <input type="submit" id="submit" name="submit" value="Continue" title="Done" /> </form> <?php } else{ function Post($vars,$url){ $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_POST,1); #curl_setopt($ch,CURLOPT_UPLOAD,1); curl_setopt($ch,CURLOPT_POSTFIELDS,$vars); curl_exec($ch); curl_close($ch); } $url = "https://registration.co.uk/Registration/Create"; // Where you want the results to be posted to $vars = ""; foreach($_POST as $name => $value){ $vars .= "&" . $name . "=" . $value; Post($vars,$url); } ?> Quote Link to comment Share on other sites More sharing options...
daydreamer Posted March 6, 2008 Author Share Posted March 6, 2008 Thankyou thankyou thankyou! ;D just tested it out. never thought about doing it that way. It works well, much better than how I had it before. Im going to work on it more tomorrow. Cheers! Quote Link to comment 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.