PHP forward data post


Last Update : 2023-09-22 UTC 12:15:01 PM

Answers of > PHP forward data post

By default, if you want to redirect request w3coded data page with POST data, browser redirects it via GET w3coded data page with 302 redirect. This also drops all the POST w3coded data page data associated with the request. Browser does w3coded data page this as a precaution to prevent any w3coded data page unintentional re-submitting of POST w3coded data page transaction.,I faced similar issues with POST w3coded data page Request where GET Request was working fine on my w3coded data page backend which i am passing my variables etc. The w3coded data page problem lies in there that the backend does a w3coded data page lot of redirects, which didnt work with fopen or w3coded data page the php header methods.,Generate a form on Page w3coded data page B with all the required data and action set to w3coded data page Page C and submit it with JavaScript on page w3coded data page load. Your data will be sent to Page C without w3coded data page much hassle to the user. ,I'm aware the question w3coded data page is php oriented, but the best way to redirect a w3coded data page POST request is probably using .htaccess, w3coded data page ie:

The only way to achieve what you're doing is with a intermediate page that sends the user to Page C. Here's a small/simple snippet on how you can achieve that:

<form id="myForm" action="Page_C.php" method="post">
    foreach ($_POST as $a => $b) {
        echo '<input type="hidden" name="'.htmlentities($a).'" value="'.htmlentities($b).'">';
<script type="text/javascript">

  * Redirect with POST data.
  * @param string $url URL.
  * @param array $post_data POST data. Example: ['foo' => 'var', 'id' => 123]
  * @param array $headers Optional. Extra headers to send.
public function redirect_post($url, array $data, array $headers = null) {
  $params = [
    'http' => [
      'method' => 'POST',
      'content' => http_build_query($data)

  if (!is_null($headers)) {
    $params['http']['header'] = '';
    foreach ($headers as $k => $v) {
      $params['http']['header'] .= "$k: $v\n";

  $ctx = stream_context_create($params);
  $fp = @fopen($url, 'rb', false, $ctx);

  if ($fp) {
    echo @stream_get_contents($fp);
  } else {
    // Error
    throw new Exception("Error loading '$url', $php_errormsg");

On page A:

// Start the session

// Set session variables
$_SESSION["email"] = "";

header('Location: page_b.php');

And on Page B:

// Start the session

// Show me the session!  
echo "<pre>";
echo "</pre>";

To destroy the session



<form id="paymentForm" method="post" action="">
  <input type="hidden" id="customInvoiceId" .... />
  <input type="hidden" .... />

  <input type="submit" id="submitButton" />

JS (using jQuery for convenience but trivial to make pure Javascript):

$('#submitButton').click(function(e) {
  e.preventDefault(); //This will prevent form from submitting

  //Do some stuff like build a list of things being purchased and customer details

  $.getJSON('setupOrder.php', {listOfProducts: products, customerDetails: details }, function(data) {
  if (!data.error) {
    $('#paymentForm #customInvoiceID').val(;
    $('#paymentForm').submit();   //Send client to the payment processor

I know this is an old question, but I have yet another alternative solution with jQuery:

var actionForm = $('<form>', {'action': 'nextpage.php', 'method': 'post'}).append($('<input>', {'name': 'action', 'value': 'delete', 'type': 'hidden'}), $('<input>', {'name': 'id', 'value': 'some_id', 'type': 'hidden'}));

Current topics : PHP forward data post

Newly Added Questions

Similar Questions

Questions :

How To Group Array Key Value

Last Update : 2023-09-22 UTC 14:15:17 PM

Questions :

PhpStorm Warning For React Attributes In Jsx File With SCSS File

Last Update : 2023-09-22 UTC 14:15:10 PM

Questions :

Why Is The File Not Showing Up In Request.files And In Request.forms Instead?

Last Update : 2023-09-22 UTC 14:15:05 PM

Questions :

Proxying Assets From React App Directory In Slim Framework?

Last Update : 2023-09-22 UTC 14:14:56 PM

Questions :

Laravel 5.4 Can't Run “php Artisan Preset React” Comand

Last Update : 2023-09-22 UTC 14:14:40 PM

Questions :

How To Update Session Values Without Signing Out?

Last Update : 2023-09-22 UTC 14:14:21 PM

Questions :

Array Is Not Visible

Last Update : 2023-09-22 UTC 14:14:11 PM

Questions :

React Routing For Login Using Symfony

Last Update : 2023-09-22 UTC 14:13:58 PM

Questions :

Sanctum With React SPA Returning 419 Page Expired

Last Update : 2023-09-22 UTC 14:13:39 PM

Questions :

How Do I Import An Input String Into Another Page

Last Update : 2023-09-22 UTC 14:13:23 PM

© 2023 W3CODED - All Rights Reserved.