Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
其他变量中的PHP会话变量_Php_Session - Fatal编程技术网

其他变量中的PHP会话变量

其他变量中的PHP会话变量,php,session,Php,Session,我有一个页面(电子商务中的购物车页面),有一些数据id,我想通过PHP访问,这样我就可以邮寄它 当我使用print\r($\u session)打印所有会话变量时我得到以下代码 我想重复“total”的值 我正在使用$\u会话['cart']['total']但它不起作用 所有其他输出(如“货币”和“语言”)按其应有的方式显示 我做错了什么 array(22) { ["sessiontoken"]=> &string(32) "2239f469b65f039885a0c74

我有一个页面(电子商务中的购物车页面),有一些数据id,我想通过PHP访问,这样我就可以邮寄它

当我使用
print\r($\u session)打印所有会话变量时我得到以下代码

我想重复“total”的值

我正在使用
$\u会话['cart']['total']但它不起作用

所有其他输出(如“货币”和“语言”)按其应有的方式显示

我做错了什么

array(22) {
  ["sessiontoken"]=>
  &string(32) "2239f469b65f039885a0c747f6595609"
  ["cart"]=>
  &object(shoppingCart)#1 (5) {
    ["contents"]=>
    array(2) {
      [216]=>
      array(1) {
        ["qty"]=>
        int(1)
      }
      [71]=>
      array(1) {
        ["qty"]=>
        int(1)
      }
    }
    ["total"]=>
    float(115.9)
    ["weight"]=>
    float(0)
    ["cartID"]=>
    &string(5) "91586"
    ["content_type"]=>
    string(8) "physical"
  }
  ["language"]=>
  &string(7) "english"
  ["languages_id"]=>
  &string(1) "1"
  ["currency"]=>
  &string(3) "USD"
  ["navigation"]=>
  &object(navigationHistory)#2 (2) {
    ["path"]=>
    array(5) {
      [0]=>
      array(4) {
        ["page"]=>
        string(9) "index.php"
        ["mode"]=>
        string(6) "NONSSL"
        ["get"]=>
        array(1) {
          ["cPath"]=>
          string(2) "50"
        }
        ["post"]=>
        array(0) {
        }
      }
      [1]=>
      array(4) {
        ["page"]=>
        string(7) "404.php"
        ["mode"]=>
        string(6) "NONSSL"
        ["get"]=>
        array(0) {
        }
        ["post"]=>
        array(0) {
        }
      }
      [2]=>
      array(4) {
        ["page"]=>
        string(21) "checkout_shipping.php"
        ["mode"]=>
        string(3) "SSL"
        ["get"]=>
        array(0) {
        }
        ["post"]=>
        array(15) {
          ["formid"]=>
          string(32) "2239f469b65f039885a0c747f6595609"
          ["action"]=>
          string(7) "process"
          ["payment"]=>
          string(5) "gspay"
          ["shipping"]=>
          string(9) "flat_flat"
          ["hd_shipping"]=>
          string(5) "12.00"
          ["hd_std_shipping"]=>
          string(5) "29.00"
          ["cust_fname"]=>
          string(1) "k"
          ["cust_lname"]=>
          string(1) "k"
          ["cust_email"]=>
          string(10) "kk@kkk.xom"
          ["cust_street"]=>
          string(3) "kkk"
          ["cust_city"]=>
          string(3) "kkk"
          ["cust_state"]=>
          string(3) "kkk"
          ["cust_zip"]=>
          string(3) "222"
          ["country"]=>
          string(2) "72"
          ["btnSubmit"]=>
          string(20) "Continue to checkout"
        }
      }
      [3]=>
      array(4) {
        ["page"]=>
        string(20) "checkout_payment.php"
        ["mode"]=>
        string(3) "SSL"
        ["get"]=>
        array(0) {
        }
        ["post"]=>
        array(0) {
        }
      }
      [4]=>
      array(4) {
        ["page"]=>
        string(25) "checkout_confirmation.php"
        ["mode"]=>
        string(3) "SSL"
        ["get"]=>
        array(0) {
        }
        ["post"]=>
        array(2) {
          ["formid"]=>
          string(32) "2239f469b65f039885a0c747f6595609"
          ["payment"]=>
          string(5) "gspay"
        }
      }
    }
    ["snapshot"]=>
    array(0) {
    }
  }
  ["user_type"]=>
  &string(5) "guest"
  ["sendto"]=>
  &NULL
  ["cartID"]=>
  &string(5) "91586"
  ["payment"]=>
  &string(5) "gspay"
  ["comments"]=>
  &NULL
  ["shipping"]=>
  &array(3) {
    ["id"]=>
    string(9) "flat_flat"
    ["title"]=>
    string(53) "Global Priority Shipping (It takes 5-7 business days)"
    ["cost"]=>
    string(5) "12.00"
  }
  ["cust_fname"]=>
  &string(1) "k"
  ["cust_lname"]=>
  &string(1) "k"
  ["cust_email"]=>
  &string(10) "kk@kkk.xom"
  ["cust_street"]=>
  &string(3) "kkk"
  ["cust_city"]=>
  &string(3) "kkk"
  ["cust_state"]=>
  &string(3) "kkk"
  ["cust_zip"]=>
  &string(3) "222"
  ["cust_country"]=>
  &string(2) "72"
  ["cust_country_title"]=>
  &string(7) "Finland"
  ["billto"]=>
  &NULL
}

看起来购物车是一个对象

因此,您应该能够通过以下方式访问:


$\u会话['cart']->总计

购物车是一个对象,因此它应该类似于

 $_SESSION['cart']->total; 
或者如果total是私有的,或者对应的类没有magic getter
\uu get()
;这可以做到(或者检查类API以获取返回
$this->total;
)的公共方法名):

从您的输出中

["cart"]=>
  &object(shoppingCart)#1 (5) {
    ...
    }
    ["total"]=>    float(115.9) 
值$\u SESSION['cart']是一个PHP对象。您应使用以下方式访问总计:

$_SESSION['cart']->total;

$\u SESSION['cart']是一个对象,那么total是它的属性:
$total=$\会话['cart']->total

['cart']->total
,因为cart是一个对象?是的,就是这样,谢谢@user1721135我相信我的答案是最通用的,因为有时对象的变量可能是私有的,并且类中没有定义_get()。如果你同意,请接受它作为回答:)谢谢!使用“代码块”在应答中编写代码。然后,您的答案将突出显示。祝你好运。谢谢你的建议。我是这里的新用户(已注册),我将努力遵守规则。
$_SESSION['cart']->total;