如何在php中将两个值从一个页面传递到另一个页面,使用session传递

时间:2016-07-21 11:52:11

标签: php

如何使用session在PHP中将两个值从一个页面传递到另一个页面。

 $account=$_SESSION["account_no"];

    $account1=$_SESSION["account_no"];

5 个答案:

答案 0 :(得分:1)

会话将在整个应用程序中(在所有页面中)提供,直到您将其销毁为止。

设置会话

<?php
session_start();
$_SESSION['variable_name_1'] = "value_1"; // or $_POST['accountno_1'];
$_SESSION['variable_name_2'] = "value_2"; // or $_POST['accountno_2'];
?>

在另一页中,获取值

<?php
session_start();
echo $_SESSION['variable_name_1'];
echo $_SESSION['variable_name_2'];

?>

答案 1 :(得分:0)

文件1:您需要在哪里保存会议帐号

<?php   // NOTICE THAT THERE IS NO SPACE BEFORE <?php [THIS IS IMPORTANT!!!]

        // FILE-NAME: file_1.php WHERE YOU HAVE TO SET THE SESSION VARIABLE
        //FIRST CHECK IF SESSION EXIST BEFORE STARTING IT:
        if (session_status() == PHP_SESSION_NONE  || session_id() == '') {
            session_start();
        }

        $_SESSION["account_no"] = $account;

文件-2:您需要从会议中获取帐户

<?php   // NOTICE THAT THERE IS NO SPACE BEFORE <?php [THIS IS IMPORTANT!!!]

        // FILE-NAME: file_2.php WHERE YOU NEED TO READ THE SESSION VARIABLE
        //FIRST CHECK IF SESSION EXIST BEFORE STARTING IT:
        if (session_status() == PHP_SESSION_NONE  || session_id() == '') {
            session_start();
        }

        // READ THE ACCOUNT NUMBER FROM SESSION DATA...
        $account = $_SESSION["account_no"];

答案 2 :(得分:0)

sessionsglobal variable

中有php

只需创建两个session variables即可使用

<?php
session_start(); // should be at top of page or before any output to browser
$_SESSION['account'] = $account;
$_SESSION['account1'] = $account1;

现在可以在任何页面的任何位置访问这些seesion variables,但应在使用前启动seesion

喜欢

<?php
session_start();
echo $_SESSION['account'];

答案 3 :(得分:0)

在第一页:

session_start();
$_SESSION['value1'] = 'First value';
$_SESSION['value2'] = 'Second value';

在第二页:

session_start();
$value1 = $_SESSION['value1'];
$value2 = $_SESSION['value2'];

答案 4 :(得分:0)

文件:1数据将存储会话

<?php
session_start(); //before HTML tag
$_SESSION['one'] = $account_no1;
$_SESSION['two'] = $account_no2;
?>

文件2:您要检索会话的位置

 <?php
    session_start();
    echo $_SESSION['one'];
    echo $_SESSION['two'];

    ?>