PHP 对象从一个页面到另一个页面?

发布于 2024-12-11 20:19:50 字数 257 浏览 0 评论 0原文

将对象从一个 PHP 页面传递到另一页面的简化方法有哪些?创建 $_SESSION 最适合这种情况吗?

提前致谢, Smccullough

更新: 我正在摆弄 Facebook PHP SDK &试图提高我的 PHP 实用知识。我想要传递的对象将包含 Facebook 专辑 ID 和专辑封面的照片 ID。该对象的大小可以小至两个专辑 ID 和两个照片 ID,也可以大于 1000 个专辑和封面照片 ID。完全取决于用户。

What are some streamline ways to pass objects from one PHP page to another? Would creating a $_SESSION best fit this situation?

Thanks in advance,
Smccullough

UPDATE:
I'm messing around with the Facebook PHP SDK & trying to better my practical PHP knowledge. The object I want to pass would contain Facebook album IDs and the photo ID for the album cover. The size of this object could be as little as two album IDs and two photo IDs, or bigger than 1000 album and cover photo IDs. Completely depends on the user.

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

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

发布评论

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

评论(5

牵你手 2024-12-18 20:19:50

$_SESSION 可能就是您想要的。替代方法是浏览器 cookie、查询字符串参数和 POST 数据。

PHP $_SESSION 示例

它是当用户未启用 cookie 时也可以使用 PHP 会话:会话 ID 传递

$_SESSION is probably what you want. Alternate methods would be browser cookies, query string parameters, and POST data.

PHP $_SESSION examples

It is also possible to use PHP sessions when users have not enabled cookies: Session ID passing

回梦 2024-12-18 20:19:50

您有几个选择:

1. pass by url (get queries)
2. pass by post (hidden form fields)
3. pass by cookie
4. pass by session

在不知道您的这些对象有多大的任何详细信息的情况下,会话很可能是最简单的,因为它们纯粹是服务器端的。传输到客户端的唯一内容是 cookie 中的会话 ID。

其他任何内容都通过客户端进行往返,并可能被黑客攻击/编辑/窃取。

You've got a few options:

1. pass by url (get queries)
2. pass by post (hidden form fields)
3. pass by cookie
4. pass by session

Without knowing any details of how big these objects of yours are, sessions are most likely the easiest, as they're purely server-side. The only thing transmitted to the client is the session ID in a cookie.

Anything else is roundtripped through the client and subject to being hacked/edited/stolen.

我喜欢麦丽素 2024-12-18 20:19:50

你应该做的是让对象休眠并将其保存到同一位置(例如:会话),然后在另一个页面中唤醒它。 睡眠和唤醒

What you should do is let the object sleep and save it to same place(etc: session), then wake it up in another page. sleep and wakeup.

各自安好 2024-12-18 20:19:50

是的,但请注意会话超时以及将有多少数据闲置。另请注意,人们可能会禁用 cookie 等。

Yes, but be aware of session time outs and how much data is going to be hanging around. Also be aware that people may have cookies disabled etc etc.

囍孤女 2024-12-18 20:19:50

实际上,这取决于它是什么数据以及您将如何处理这些数据。

正如前面提到的,您可以使用以下方法之一:

  1. 通过表单传递
  2. 通过 cookie 传递
  3. 通过会话变量传递
  4. 通过数据库传递(即保存到数据库,然后在下一页上从中读取 - 仍然需要某种会话或cookie来存储数据库中表的id)

我个人喜欢使用会话或cookie,或者如果我希望能够在以后跟踪/调试它的信息,那么将其保存到数据库通常是一个好主意。

如果您可以更深入地了解您尝试存储的对象,我将能够提供进一步的帮助。

Really it depends what data it is and what you are going to be doing with that data.

you can, as previously mentioned use one of these methods:

  1. pass via form
  2. pass via cookie(s)
  3. pass via session variable(s)
  4. pass via database (i.e. saving to database then reading from it on next page - still requires some kind of session or cookie to store an id for the table in the database though)

I personally like to either use sessions or cookies, or if its information I want to be able to track/debug at a later date then saving it to the database is often a good idea.

If you could provide more insight into what objects you are trying to store I'd be able to help further.

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