dongtao9887 2015-01-11 13:24
浏览 26
已采纳

获取会话内的数组的元素和值

I need to get the elements and values from an array that is coming via session from another page.

So this is page one

if (!$error) {
                session_start();
                $user_info = array
                (
                    'fullName' => $fullName,
                    'street_address' => $street_address,
                    'city' => $city,
                    'state' => $state,
                    'zip' => $zip,
                    'country' => $country,
                    'email' => $email,
                    'phone' => $phone,
                    'planName' => $planName,
                    'planPrice' => $planPrice
                );
                $_SESSION['user_info'] = $user_info;
                header("Location:?pid=18&pmh=3");
            }

And this is page two that I need to get the values here

 <?php
var_dump($_SESSION['user_info']);

$proDetails = array(
    "proName"=>"this is the pro name"
);

require_once 'payment-api/Twocheckout.php';

Twocheckout::privateKey('4D67BA12-CE09-4F1D-AB20-0133F24E3472');
Twocheckout::sellerId('901249656');
Twocheckout::sandbox(true);

try {
    $charge = Twocheckout_Charge::auth(array(
        "merchantOrderId" => "123",
        "token" => $_POST['token'],
        "currency" => 'USD',
        "total" => '10.00',
        "billingAddr" => array(
            "name" => $_SESSION["user-info"]["fullName"],
            "addrLine1" => '123 Test St',
            "city" => 'Columbus',
            "state" => 'OH',
            "zipCode" => '43123',
            "country" => 'USA',
            "email" => 'example@2co.com',
            "phoneNumber" => '555-555-5555'
        )
    ));

    if ($charge['response']['responseCode'] == 'APPROVED') {
        echo "Thanks for your Order!";
        echo "<h3>Return Parameters:</h3>";
        echo "<pre>";
        echo "His name" . $charge['response']['billingAddr']['name'];
        var_dump( $charge );
        echo "<br />";
        echo $proDetails['proName'];
        echo "</pre>";
    }
} catch (Twocheckout_Error $e) {
    print_r($e->getMessage());
}

now as you can see I need to replace the 'Testing Tester' with my value coming from session.

I try to do so "name" => $_SESSION["fullName"], but it didn't work.

and this is the var_dump of var_dump($_SESSION['user_info']);

is

array(8) { ["fullName"]=> string(6) "Yousef" ["street_address"]=> string(11) "this is ass" ["city"]=> string(5) "Cairo" ["state"]=> string(8) "Bassteen" ["zip"]=> string(7) "2125454" ["country"]=> string(3) "EGY" ["email"]=> string(21) "johnef_sh@hotmail.com" ["phone"]=> string(11) "01224853582" } Thanks for your Order!
  • 写回答

1条回答 默认 最新

  • doutuo7156 2015-01-11 13:29
    关注

    Simple. The fullName variable is a part of the array which is stored as a variable in SESSION array .So :

    $_SESSION["user_info"]["fullName"]
    

    To set the variable :

    "name" => $_SESSION["user_info"]["fullName"]
    

    Remember, in php N dimensional arrays are possible (Of course limited be your hardware).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动