[英]passing php variables between different pages that are linked trough anouther page
我是PHP世界的新手,我要做的是將3個變量從let say example.php發送到下一頁example1.php ,將相同的變量發送到第三頁example3.php ,
對我來說問題是,當它們在$_POST
發布時,它們在example1.php中可見,我將它們分配給另一個變量並再次通過$ _POST將它們發布到example3.php,這是如何在頁面之間重定向而不是發送表格方法=“發布”
echo "<meta http-equiv=Refresh content=0;url=example1.php>";
在第二種形式,我發送方法=“發布”
我所嘗試的是使用Cookies,但是每次瀏覽器都不能正常工作,當用戶點擊“后退”按鈕並輸入舊條目時,舊條目仍然存儲等等,
有人曾建議通過$_GET
在URL上發送它們,但我發送了敏感數據。
我的應用程序是外部實體的郵件注冊,連接到外包的數據庫(example.php),如果驗證完成且正確,則變量被發送到用戶放置其電子郵件和密碼的其他頁面(example1.php),在第三個(example3.php)中輸入的所有設置都被處理,因此我無法從第一頁到最后一頁獲取數據。
也許最好的方法是使用會話變量
在第1頁
session_start();
$_SESSION['yourvariable'] = 'foo';
在第2頁
session_start();
$foo = $_SESSION['yourvariable'];//$foo = 'foo';
您可以嘗試使用以下代碼:
/** example.php */
* You must put on the very first line of you page
*/
<?php session_start(); ?>
// These codes can be anywhere after the above
<?php
$_SESSION['varName1'] = 'Value 1';
$_SESSION['varName2'] = 'Value 2';
$_SESSION['varName3'] = 'Value 3';
// You can test to see the result here:
echo 'varName1 Value: '.$_SESSION['varName1'].'<br />';
echo 'varName2 Value: '$_SESSION['varName2'].'<br />';
echo 'varName3 Value: '$_SESSION['varName3'].'<br />';
// You can print anywhere after here or
// you can update their values up to you.
?>
/** example1.php */
* You must put on the very first line of you page
*/
<?php session_start(); ?>
// These codes can go anywhere in your page after above line
<?php
// You can print the 3 values from example.php
echo 'varName1 Value: '.$_SESSION['varName1'].'<br />';
echo 'varName2 Value: '$_SESSION['varName2'].'<br />';
echo 'varName3 Value: '$_SESSION['varName3'].'<br />';
// You can print anywhere after here or
// you can update their values up to you.
?>
/** example2.php */
* You must put on the very first line of you page
*/
<?php session_start(); ?>
// These codes can go anywhere in your page after above line
<?php
// You can print the 3 values from example.php, example2.php
echo 'varName1 Value: '.$_SESSION['varName1'].'<br />';
echo 'varName2 Value: '$_SESSION['varName2'].'<br />';
echo 'varName3 Value: '$_SESSION['varName3'].'<br />';
// You can print anywhere after here or
// you can update their values up to you.
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.