我是PHP世界的新手, 我要做的是将3个变量发送到下一页 example1.php ,将相同的变量发送到第三页 example3 .php ,
对我来说问题是,当它们在$_POST
中发布时,它们在example1.php中可见,我将它们分配给另一个变量并再次通过$ _POST将它们发布到example3.php
这是如何在页面之间重定向而不是通过send form method =“post”
echo "<meta http-equiv=Refresh content=0;url=example1.php>";
,在第二种形式中,我发送方法=“post”
我所尝试过的是使用Cookie,但是当用户点击“后退”按钮并输入新条目时,它在每个浏览器上都不起作用,旧条目仍然存储等等,
有人曾建议$_GET
在网址上发送这些内容,但我发送的是敏感数据。
我的应用程序是外部实体的邮件注册,连接到外包的数据库(example.php)如果验证完成且正确,变量将被发送到用户放置其电子邮件的其他页面(example1.php)和密码,并在第三个(example3.php)处理所有输入的设置,所以我无法从第一页到最后一页获取数据。
答案 0 :(得分:2)
也许最好的方法是使用session变量
第1页
session_start();
$_SESSION['yourvariable'] = 'foo';
第2页
session_start();
$foo = $_SESSION['yourvariable'];//$foo = 'foo';
答案 1 :(得分:0)
您可以尝试使用以下代码:
/** 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.
?>