Jump to content

why isn't this POST form submitting properly via CURL?


bitt3n

Recommended Posts

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> 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.