![](/img/trans.png)
[英]Is there any way in PHP to store $variable of $variable in session
[英]php fails to store any _SESSION or _GLOBALS variable
我在file1.php中存儲一個會話和一個全局變量。 但是,當我嘗試從file2.php訪問那些文件時,我什么也沒得到。 我正在使用PHP 5.1.6。
$_SESSION['abc'] = $a;
$GLOBALS['def'] = $b;
任何想法?
提前致謝。
關於您的編輯:$ GLOBALS中存儲的變量只是該腳本的全局變量。 您必須將值放在$ _SESSION中才能在頁面之間使用。
例:
// Page 1
session_start();
$_SESSION['abc'] = "hello world";
$GLOBALS['def'] = "More stuff.";
// Page 2
session_start();
echo $_SESSION['abc']; // prints 'hello world'
echo $GLOBALS['def']; // is not defined. Globals aren't session variables.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.