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(); 
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题