如何使用session在PHP
中将两个值从一个页面传递到另一个页面。
$account=$_SESSION["account_no"];
$account1=$_SESSION["account_no"];
答案 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)
嗨sessions
在global 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'];
?>