Reputation: 363
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.
Upvotes: 0
Views: 146
Reputation: 6346
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.
Upvotes: 1
Reputation: 360662
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.
Upvotes: 1
Reputation: 31280
$_SESSION
is probably what you want. Alternate methods would be browser cookies, query string parameters, and POST data.
It is also possible to use PHP sessions when users have not enabled cookies: Session ID passing
Upvotes: 2
Reputation: 47609
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.
Upvotes: 1
Reputation: 160833
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.
Upvotes: 1