I was wondering if anyone can help with posting $_POST
values again. Let's say I post form values to post.php where I can access data by $_POST or $_REQUEST variables. But how can I post $_POST to another url let's say post_one.php and access data there?
You have to issue a HTTP POST request to your url. A option is to do this using file_get_contents and provide a context. Creating a context is easy using stream_context_create. An example is the following:
$data = http_build_query(
array(
'first' => 'your first parameter',
'second' => 'your second parameter'
)
);
$headers = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $data
)
);
$context = stream_context_create($headers);
$result = file_get_contents($url, false, $context);
This will issue a POST request to $url. $_POST['first']
and $_POST['second']
will be available in your target url.
If you want to re-post all posted variables, replace the first line with:
$data = http_build_query($_POST);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With