duancheng8000 2016-07-26 23: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-26 23: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 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部