如何使用$ _ post永远更改某些内容

发布于 2025-01-21 21:20:56 字数 514 浏览 2 评论 0原文

我正在尝试将数据从网站填充到另一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鲜肉鲜肉永远不皱 2025-01-28 21:20:56

continue

You can use the PHP SESSION feature to keep the data persistent:

in b.php:

<?php
   // Start the session
   session_start();

   // save the input var as a SESSION property
   if (isset($_POST['mp'])) {
      $_SESSION['content'] = $_POST['mp'];
   }

   // display the property
   echo "you entered " . $_SESSION['content'];
蔚蓝源自深海 2025-01-28 21:20:56

一般而言,您要做的是将$ _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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文