2

I've been trying to submit below form using PHP curl but it gives me no access, when I just open the HTML file with below code and press submit, it works!

   <form action="http://www.example.com/47595ADEDFGVB558S" method="post">
          <input type="submit" name="warning" value="Yes, let me in">
    </form>

Here is my PHP block

    $url = 'http://www.example.com/47595ADEDFGVB558S';
    $data = array('warning' => 'Yes, let me in' );

$agent= 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)';

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_REFERER, $url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt ($ch, CURLOPT_POST, 1);
    curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($data);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);    
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, $agent);
    $returndata = curl_exec($ch);
    curl_close($ch);
    echo $returndata ;

Headers when submitted via browser

Request Method:POST
Status Code:302 Moved Temporarily
Request Headersview source
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8,fr;q=0.6
Cache-Control:max-age=0
Connection:keep-alive
Content-Length:25
Content-Type:application/x-www-form-urlencoded
Host:www.example.com
Origin:http://www.example.com
Referer:http://www.example.com/47595ADEDFGVB558S
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36
Form Dataview sourceview URL encoded
warning:Yes, let me in

where am I doing wrong? I tried setting origin, host headers but i think error is with the data being submitted.

Naveen Gamage
  • 1,844
  • 12
  • 32
  • 51
  • so you're not replicating something which the normal form submission does.figure out what the difference is and off you go. – Marc B Mar 16 '14 at 13:48
  • Is it not good to practise or give it a try to override a normal submission. – Naveen Gamage Mar 16 '14 at 13:53
  • @RyanVincent thanks! problem was with the headers that were being sent with the curl request. Just had to add couple of headers. – Naveen Gamage Mar 23 '14 at 17:01
  • 2
    @NaveenGamage next time, you should answer your question with your updated code, so future visitors can see a viable solution. Please help your questions to benefit everyone, thanks! – carbide20 Sep 26 '16 at 14:01

0 Answers0