如何使用$ _ post永远更改某些内容
我正在尝试将数据从网站填充到另一个Wensite: A.html:
<form action="b.php" method="post">
<textarea id="myProjects" name="mp"></textarea>
<input id="submit" type="submit" value="Submit" />
</form>
在B.PhP中:
<?php $content=$_POST['mp'];
echo "you entered ".$content;
?>
这以非常奇怪的方式起作用,当我单击“提交”按钮时,我将被指向B.PHP页面,我可以看到我输入的内容。但是,如果我重新加载此页面,而不是刷新,我的内容消失了,然后投掷警告:未定义的数组键“ MP”
看起来像从$ _post接收到的数据是“暂时”存储的。我是PHP的新手,所以我不确定该如何解决。
I am trying to populate data from a website to another wensite:
a.html:
<form action="b.php" method="post">
<textarea id="myProjects" name="mp"></textarea>
<input id="submit" type="submit" value="Submit" />
</form>
in b.php:
<?php $content=$_POST['mp'];
echo "you entered ".$content;
?>
This works in a very strange way, when I click submit button, I am directed to the b.php page, and I can see what I entered. But if I reload this page, not refresh, my contents disappear, and throwWarning: Undefined array key "mp"
It looks like data received from $_POST is "temporarily" stored. I am new to PHP, so I am not sure how can I figure it out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
continue
You can use the PHP SESSION feature to keep the data persistent:
in b.php:
一般而言,您要做的是将$ _post ['mp']的值存储到$ _Session变量中,以便它从一个页面请求持续到下一个。
但是,通过直接操纵这些变量来做到这一点通常是不好的做法。除非您对用户输入进行消毒,否则您将接受无数的脚本攻击。尽管涉及一些学习,但使用已建立的PHP框架(例如Laravel),您最好,该框架具有完整的验证功能,并管理为您开始会话的过程。一个好的框架也将以许多其他方式为您提供帮助。
Generally speaking, what you want to do is to store the value of $_POST['mp'] into the $_SESSION variable so that it persists from one page request to the next.
However doing it by manipulating these variables directly is generally bad practice. Unless you sanitize the user input you are open to a myriad of scripting attacks. Although there is some learning involved, you are much better off using an established PHP framework (for example Laravel), which has a full set of validation functions, and manages the process of starting the session for you. A good framework will also help you in many other ways.