WordPress PHP: The variables are lost on the redirected page

I made a simple form in WordPress as follows:

<form action="../process.php" method="post" name="myForm">

vol_single <input id="vol_single" type="text" name="vol_single" />
rate_single <input id="rate_single" type="text" name="rate_single" />

<input type="submit" value="Submit" /></form>

and here is process.php:

Read More
<?php 
session_start();
  $vol_single = $_POST['vol_single'];

  $rate_single = $_POST['rate_single'];

  $rate_total=12*($vol_single*$rate_single);

//Redirects to the specified page
header("Location: http://..."); 
exit();
?>

I’m trying to display the calculated value on the redirected page in WordPress. I have tried this:

[insert_php]
echo 'total rate:';
echo $rate_total;
[/insert_php]

It does not display any values. Could anyone help?

Related posts

1 comment

  1. You wouldn’t have access to the variables after a redirect. The life time of your variables end after the execution of each script.

    To achieve such, you could either store the variables inside sessions or append them to the end of the redirect target and access them from $_GET superglobals on the new page like so:

    First Page:
    header("Location: http://example.com?total=$rate_total");
    
    Second Page:
    echo 'Total is: ' . $_GET['total'];
    

    You can find a quick introduction to sessions here.

Comments are closed.