bitt3n Posted August 15, 2011 Share Posted August 15, 2011 I'm trying to submit a POST form in order to input a given location (eg United Kingdom), then visit another page on the same site to obtain price information for this location. (I have permission to use this price data.) I'm pretty sure I'm screwing up submitting the POST form somehow. If I display the output of the first call to curl_exec($ch) I get 'Object moved to here.' with a link to default.aspx. What's the best way to fix this? <?php // STEP 1. let's create a cookie file $ckfile = tempnam ("/tmp", "CURLCOOKIE"); // STEP 2. visit the homepage to set the cookie properly $ch = curl_init ("http://www.pret-a-beaute.com/ChangeSeason.aspx"); curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt ($ch, CURLOPT_POST, true); curl_setopt( $ch, CURLOPT_POSTFIELDS, 'Country="67"'); curl_exec ($ch); curl_setopt ($ch, CURLOPT_POST, false); /* STEP 3. visit cookiepage.php */ $ch = curl_init ("http://www.pret-a-beaute.com/Whatsnew.aspx?CategoryId=0&Direction=0&OrderBy=36&ViewAll=1&PageNo=1&TopCatAll=1&TableLookupStr="); curl_setopt ($ch, CURLOPT_COOKIEFILE, $ckfile); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec ($ch); echo($output); ?> the form in question is <form method="post" action="ChangeSeason.aspx" name="ChangeSeason"> <table align=center width="100%" border="0" cellspacing="5" cellpadding="0"> <tr> <td align=left class="MAINTEXTBLACKsmall" style="padding-left:75px;"> COUNTRY </td> </tr> <tr> <td align=center> <select name="Country" id="Country" class="selectbox" onchange="ChangeSeason.submit();"><option value=0>CHOOSE YOUR COUNTRY</option> <option value="67">United Kingdom</option> <option selected value="66">USA</option> </select> </td> </tr> </table> </form> Quote Link to comment https://forums.phpfreaks.com/topic/244854-why-isnt-this-post-form-submitting-properly-via-curl/ Share on other sites More sharing options...
bitt3n Posted August 16, 2011 Author Share Posted August 16, 2011 I figured it out, I should have established the second URL via curl_setopt() rather than curl_init(), which resets the cookie location etc Quote Link to comment https://forums.phpfreaks.com/topic/244854-why-isnt-this-post-form-submitting-properly-via-curl/#findComment-1258206 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.