PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
# set the post fields and values
$data = array(
'foo' => 'bar',
'bar' => 'foo',
);
# create the post string
$post_fields = '';
foreach ($data as $k => $v) $post_fields .= "$k=" . urlencode($v) . '&';
# initialize curl
$ch = curl_init('http://example.com/page.php');
# don't return the header
curl_setopt($ch, CURLOPT_HEADER, 0);
# return the resulting data rather than displaying it
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
# tell curl we are posting data
curl_setopt($ch, CURLOPT_POST, 1);
# set the post data
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
# don't validate ssl certs
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
# execute and get the response
$response = curl_exec($ch);
# close curl
curl_close($ch);
# echo response
echo $response;
Thanks ldougherty and astions. However, I am very familiar with cURL. I don't want to download the actual page and save it as a variable. I want to forward the browser to the actual page, just like I was doing:
The headers are what you send to the browser, not to the page you are going to redirect to.
I don't know other way to redirect with POST then to display a form and to immediately submit it