Is it possible to send POST data with header() in PHP?
It is not possible to send POST data with the header() function in PHP. To send POST data, you can use cURL or the file_get_contents() function with stream context options to make an HTTP request with the desired POST data.
$data = array('key1' => 'value1', 'key2' => 'value2');
$options = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents('http://example.com/submit.php', false, $context);
echo $result;
Keywords
Related Questions
- How can PHP be used to dynamically change content within a website based on user interactions?
- How does setting ATTR_EMULATE_PREPARES to false in PDO affect memory usage and query execution compared to mysqli?
- How can the API of wolframalpha.com be utilized to calculate derivatives of mathematical functions in PHP?