【问题标题】:Carrying a Submitted Name Variable across multiple php pages?跨多个 php 页面携带提交的名称变量?
【发布时间】:2016-06-12 05:52:09
【问题描述】:

在我的第一页:page1.php 我有一个输入,您可以在其中输入您想要的名称,然后我希望将其转移到多个页面,到目前为止我可以将它放到 page2.php 但在 page3.php这里的代码失败是我的代码

page1.php:

       <form action="page2.php" method="post">
Name:  <input type="text" name="username" />
       <input type="submit" name="submit" value="Submit" />

\

page2.php:(5秒后页面重定向到page3.php)

<?php
echo $_SESSION['username'] = $_POST['username'];
?>
<form action="page3.php" method="post">
<input type="hidden" name="username" />

page3.php:

<?php
echo $_SESSION['username'] = $_POST['username'];
?>     

这些行在 page2.php 上有效,但在此处无效,这是我似乎无法解决的问题

【问题讨论】:

标签: php html


【解决方案1】:

不给你鱼,我教你钓鱼:

echo $_SESSION['username'] = $_POST['username'];

此语句将值 ASSIGNED 回显给$_SESSION['username']

  =  Assignment
 ==  Comparison
===  Comparison (Identical)

【讨论】:

    【解决方案2】:

    在 page3.php 上不起作用,因为您没有传递任何值。所以:

    代替:

    <input type="hidden" name="username" />
    

    去:

    <input type="hidden" name="username" value="".$_SESSION['username']."">
    

    或者:

    <input type="hidden" name="username" value="".$_POST['username']."">
    

    现在它传递了值,您应该在 page3.php 上获取值。一个警告是用户可以使用 DEV 工具编辑您的值,因此我建议以不同的方式传递值。

    【讨论】:

      猜你喜欢
      • 2010-10-10
      • 2014-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-26
      相关资源
      最近更新 更多