使用php会话将值从一个页面发送到另一个页面[重复]
This question already has an answer here:
Im using wordpress
I wanted to send the data that is collected by form in the first page to the next page
I didn't find anything that can send array data to another page other than GET command, GET commands uses URL, The reason I'm not using this GET is the sending information includes price values that are calculated using entered information
I found this $_session seems ok to my case (If any others are available, please tell me), Used wp session manager plugin to use $_SESSION.
im using it like this,
if(!isset($_SESSION)){
session_start();}
if(isset($_GET['B2'])) {
$_SESSION["info"] = "user-form";
$_SESSION["weight"] = $weight;
$_SESSION["price"] = $weight;
buy_now(); }
The B2 is a buy now button
function buy_now(){
if(isset($_GET['B2'])) {
header("Location:".get_site_url()."/buy-now/");
}
if(!isset($_SESSION)){
session_start();}
echo $_SESSION["info"]."<br>";
echo $_SESSION["weight"]."<br>";
echo $_SESSION["price"]."<br>";
}
The weight and price are Undefined index, the info will display.
What is the problem here? and How can I send variables to another page?, I'm unable to find any solution for now. Please help with this...
Thank you
</div>
whenever you are need to check the session is start of not you should not check ist with $_SESSION you need to check the session_id() is generated or not (check the post for check the session start Check if PHP session has already started)
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
if(isset($_GET['B2'])) {
$_SESSION["info"] = "user-form";
$_SESSION["weight"] = $weight;
$_SESSION["price"] = $weight;
buy_now();
}
word press provide another method like wp_cache_get / wp_cache_set
which you can use as own CMS method for passing data from one page to another page by define expiry time as well.
I think you have to try POST method.
<form action="test.php" method="post">
<input type="text" name="my_value" value="value"/>
...
</form>
On next page
<?php echo $_POST['my_value'];?>
That's it.
Refer https://codex.wordpress.org/Class_Reference/WP_Object_Cache for detailed explanation and remember to delete / reset as per your use case else might be a problem.