PHP 对象从一个页面到另一个页面?
将对象从一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
$_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
examplesIt is also possible to use PHP sessions when users have not enabled cookies: Session ID passing
您有几个选择:
在不知道您的这些对象有多大的任何详细信息的情况下,会话很可能是最简单的,因为它们纯粹是服务器端的。传输到客户端的唯一内容是 cookie 中的会话 ID。
其他任何内容都通过客户端进行往返,并可能被黑客攻击/编辑/窃取。
You've got a few options:
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.
你应该做的是让对象休眠并将其保存到同一位置(例如:会话),然后在另一个页面中唤醒它。 睡眠和唤醒。
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.
是的,但请注意会话超时以及将有多少数据闲置。另请注意,人们可能会禁用 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.
实际上,这取决于它是什么数据以及您将如何处理这些数据。
正如前面提到的,您可以使用以下方法之一:
我个人喜欢使用会话或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:
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.