duancheng8000
2016-07-27 07:09
浏览 40
已采纳

使用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>
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • dongwu5801 2016-07-27 07:19
    已采纳

    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(); 
    }
    
    已采纳该答案
    打赏 评论
  • doubeiji2602 2016-07-27 07:15

    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.

    wp_cache_set

    wp_cache_get

    打赏 评论
  • doupa8922 2016-07-27 07:35

    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.

    打赏 评论
  • doumubi6784 2016-07-27 07:41

    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.

    打赏 评论

相关推荐 更多相似问题