0

I need to send POST data to the remote form. I have a simple script...

$data['field1'] = '1';
$data['field2'] = '2';
$data['field3'] = '3';  

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.example.com/my-form.php?authToken=poWQyj2q");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

$output = curl_exec($ch);
$info = curl_getinfo($ch);

curl_close($ch);

echo $output; 

... It would be work nice, but there is a problem with form URL - How you can see, there is some "authToken" value which changes each time a page is loaded. When it is incorrect, the form is sent, but not processed.

Any ideas how to solve it? Thanks.

Muhammad Umair
  • 1,664
  • 2
  • 20
  • 28
zaziD
  • 15
  • 1
  • 6

1 Answers1

0
  1. Request the page containing the form
  2. Extract the auth token from the DOM
  3. (Presumably) store the cookie value
  4. Make your request but also include the auth token and the cookie
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335