【问题标题】:How to print previous page data to current page in php?如何在php中将上一页数据打印到当前页面?
【发布时间】:2016-11-03 04:34:09
【问题描述】:

如何在当前页面显示用户在登录页面输入的NAME字段数据?
详情

1.用户将在下面的页面中输入用户名和密码,该页面保存为“home.html”。

<form action="indexpage.php" method="post">
<p>Username</p> 
<input name="myusername" type="text" id="myusername" required>
<p>Password</p>
<input name="mypassword" type="password" id="mypassword"required></br>
<button><img src="http://icons.iconarchive.com/icons/webiconset/application/32/Register-icon.png"  /></button>
</form>  

2.点击登录按钮后,这将重定向到这个页面(下面是脚本)并保存为“indexpage.php”。

<html>
<form method="post" action="insert1.php">
<div style="text-align:center">
<button>INSERT<img src="http://brandonmadeawebsite.com/images/art/icons/insert_icon.png"  height="30" /></button> </div>
</form>
</html>

3.现在如果我从选项中选择插入选项,它将重定向到“insert1.php”页面

<p>
<label>ENTER NAME</label>
<input type="text"  name="name"  value="<?php print $myusername;    ?>" required>

我正在尝试在进入此页面后立即打印 USERNAME 字段。
请帮助我,在此先感谢

【问题讨论】:

  • 您可以将此数据保存到session,然后通过$_SESSION在其他页面上使用
  • 当您将公式数据发送到“indexpage.php”时,数据将保存在$_POST 数组中。因此您可以通过$_POST['myusername'] 访问用户名,例如

标签: php html


【解决方案1】:

没有会话技术

你可以修改indexpage.php

的代码
<html>
<form method="post" action="insert1.php">
<div style="text-align:center">
<input type="hidden" name="username" value="<?php echo $_POST['username'] ?>">
<input type="hidden" name="password" value="<?php echo $_POST['password'] ?>">
<button>INSERT<img src="http://brandonmadeawebsite.com/images/art/icons/insert_icon.png"  height="30" /></button> </div>
</form>
</html>

现在第一个表单的值可供第三个表单提交

在第三页

<label>ENTER NAME</label>
<input type="text"  name="name"  value="<?php print $_POST['username'];    ?>" required>

【讨论】:

  • 危险:此代码是vulnerable to XSS。用户输入在插入 HTML 文档之前需要转义!
  • 它没有在 insert1.php 页面中打印名称。
  • 它在 index1.php 页面中没有打印名称
  • 不要粗鲁@MeeneshJain,而是更新你自己的答案?
  • 在第三页将myusername 更改为username
【解决方案2】:

您需要启动一个会话,并在用户登录时保存您的用户名:

session_start();
$_SESSION['username']= $youreval;

当你想使用它时,别忘了把它放在你的脚本中(在顶部):

session_start(); 

【讨论】:

  • 当您在登录页面时,最好开始使用 session,如果需要,他可以使用 $_POST,但最好使用 session,这样他就可以在每个页面上重复使用用户名,而不仅仅是第+1页
  • 我不知道为什么这被否决了,它一个选项
猜你喜欢
  • 2010-10-09
  • 2019-01-13
  • 1970-01-01
  • 2020-10-19
  • 1970-01-01
  • 2017-06-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多