PHP将变量传递到下一页这看起来很简单,但我找不到一个好办法。比如说在第一页我创建了一个变量$myVariable = "Some text";该页面的表单操作是“Page2.php”。因此,在Page2.php中,如何访问该变量?我知道我可以通过会话来完成这个任务,但是我认为对于一个简单的字符串来说,这太过了,我只需要传递一个简单的字符串(一个文件名)。我怎样才能做到这一点?谢谢!
3 回答
![?](http://img1.sycdn.imooc.com/5333a1d100010c2602000200-100-100.jpg)
慕姐8265434
TA贡献1813条经验 获得超2个赞
<?php session_start();$_SESSION['regName'] = $regValue;?><form method="get" action="get_reg.php"> <input type="text" name="regName" value=""> <input type="submit"></form>
<?php session_start();$regValue = $_GET['regName'];echo "Your registration is: ".$regValue.".";?><p><a href="set_reg.php">Back to set_reg.php</a>
![?](http://img1.sycdn.imooc.com/545863080001255902200220-100-100.jpg)
holdtom
TA贡献1805条经验 获得超10个赞
在请求中传递数据
echo '<input type="hidden" name="myVariable" value="'. htmlentities($myVariable).'">';
echo '<form method="POST" action="Page2.php?myVariable='. urlencode($myVariable).'">";
在会话中传递数据
保安
- 3 回答
- 0 关注
- 714 浏览
添加回答
举报
0/150
提交
取消