Smccullough
Smccullough

Reputation: 363

PHP objects from page to page?

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

Answers (5)

Nick
Nick

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:

  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.

Upvotes: 1

Marc B
Marc B

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

pix0r
pix0r

Reputation: 31280

$_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

Upvotes: 2

Joe
Joe

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

xdazz
xdazz

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

Related Questions