php 请求/发布/获取/会话过期

发布于 2024-09-26 04:10:43 字数 436 浏览 0 评论 0原文

我知道 SESSION 可能会过期,但是 $_REQUEST/$_POST/$_GET 变量呢?

我的问题是,我有提交信息的用户,在将其插入数据库之前,我需要为该信息设置一个 ID。现在我考虑使用 SESSION,但问题是如果会话在用户将信息提交到数据库之前过期,他们就会丢失我需要的 Id。将 $_REQUEST/$_POST/$_GET 变量传递给它是否是一个更好的解决方案,或者我应该只使用一个变量并重新调整脚本?

另外,我使用了 SESSION,因为从函数内部调用它很容易,而无需传入它。

function setInfo() {
   // no need to pass I can call from within
   $Id = $_SESSION['Id'];
}

这是一个好的做法吗?

编辑: 如果把它做成饼干会更好吗?

I know a SESSION can expire but what about $_REQUEST/$_POST/$_GET variables?

My question is, I have users that submit information and I need to set a Id for that information before I insert it into a database. Now I thought about using a SESSION but the problem is if the session expires before the user has submitted the information to the database they loose the Id I need. Would passing it the $_REQUEST/$_POST/$_GET variable(s) be a better solution or should I just use a variable and readjust the script?

Also I was using SESSION as it's very easy to call from inside a function without passing it in.

function setInfo() {
   // no need to pass I can call from within
   $Id = $_SESSION['Id'];
}

Is this good practice?

EDIT:
Would this be better as a cookie?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

我还不会笑 2024-10-03 04:10:43

我的第一个问题是,您是否无法插入行并使用 @@IDENTITY 检索自动递增 ID?您不能真正将数据“存储”在 $_REQUEST、$_POST 或 $_GET 中,该数据仅在客户端向服务器提交页面、表单、链接请求时到您完成并发送以输出结果页面时才存在。 。无论哪种方式,您很可能会使用 $_SESSION 空间来存储需要传送到其他页面的信息。

My first question would be, are you not able to insert a row and retrieve a auto-incrementing ID with @@IDENTITY?. you can't really "Store" data in $_REQUEST, $_POST or $_GET, that data is only there from when the client submits a page, form, link request to the server to when you finish and send to output the resulting page. Either way, you would most likely use the $_SESSION space to store the info that needs to be carried to other pages.

走过海棠暮 2024-10-03 04:10:43

您可以在表单中使用隐藏字段,并将隐藏字段的存储在数据库中(“也许或很可能”为此您需要一个单独的表)。当用户提交表单时,您会检查数据库中是否存在提交的隐藏变量的

当处理来自特定的请求时,将其从数据库中删除。

You can use a hidden field in the form, and store the the value of hidden field in database ("maybe or very probably" you will need a separate table for this). When user submits the form you check that the submitted value for hidden var exists in the database.

When the request from particular value is processed, delete it from database.

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