How can a PHP script automatically fill out and submit a form to a specific URL?
To automatically fill out and submit a form to a specific URL using PHP, you can use the cURL library to send a POST request with the form data included. You will need to inspect the form fields on the target website to determine the data to be submitted. Make sure to set the appropriate headers and handle any redirects that may occur.
<?php
// URL of the form to submit
$url = 'https://example.com/form-submit';
// Form data to be submitted
$formData = array(
'field1' => 'value1',
'field2' => 'value2',
'field3' => 'value3'
);
// Initialize cURL session
$ch = curl_init();
// Set cURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($formData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute cURL session
$response = curl_exec($ch);
// Close cURL session
curl_close($ch);
// Output the response
echo $response;
?>