在通过另一个uther页面链接的不同页面之间传递php变量


passing php variables between different pages that are linked trough anouther page

我是PHP世界的新手,我想做的是将3个变量从example.php发送到下一页sample1.php,并将相同的变量发送到第三页example3.php

对我来说,问题是,当在$_POST中发布它们时,它们在example1.php中可见,我将它们分配给另一个变量,并通过$_post再次将它们发布到example3.php这就是我如何在页面之间重定向,而不是通过发送表单method="post"

echo "<meta http-equiv=Refresh content=0;url=example1.php>";

在第二种形式中,我用方法="张贴"发送它们

我尝试过的是使用Cookies,但它并不是每次都能工作,在每个浏览器上,当用户点击"后退"按钮并输入新条目时,旧条目仍在存储,等等,

有人建议通过$_GET在URL上发送它们,但我正在发送敏感数据。

我的应用程序是一个外部实体的邮件注册,它连接到外包的数据库(example.php)。如果验证完成且正确,变量会被发送到用户放置电子邮件和密码的另一个页面(example1.php),在第三个页面(示例3.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.
?>