簡體   English   中英

Wordpress PHP:變量在重定向頁面上丟失

[英]Wordpress PHP: The variables are lost on the redirected page

我在Wordpress中制作了一個簡單的表格,如下所示:

<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>

這是process.php:

<?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();
?>

我正在嘗試在Wordpress中的重定向頁面上顯示計算出的值。 我已經試過了:

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

它不顯示任何值。 有人可以幫忙嗎?

重定向后,您將無權訪問變量。 變量的生命周期在每個腳本執行后結束。

為此,您可以將變量存儲在會話中,也可以將其附加到重定向目標的末尾,然后從新頁面上的$ _GET superglobals訪問它們,如下所示:

First Page:
header("Location: http://example.com?total=$rate_total");

Second Page:
echo 'Total is: ' . $_GET['total'];

您可以在此處找到會話的快速介紹。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM