views:

59

answers:

5

Well, I have a new project, and I've not done anything like it before, but so far so good. I am in need of having to pass some data from one page to another, and there is no limit to the amount of data that gets passed.

At first, I was thinking of POST-ing it, and then when each page loads, just grab the POST data, and store it in an array, but to me that sounds a bit too overe complicated or something for what I want to do.

Then I thought about HTML5 and localStorage, but since there is a limit on localStorage, and the fact that the majority of users browsers still don't support it yet (that is, the majority of my clients customers browsers), that's a big no no, at this point.

So, now I'm all out of ideas.

Here's what I'm trying to do, it sounds pretty simple to me, yet I can't figure out how to go about it:

On any given page, there are a probably over a hundred links, each link represents either a name of a product or information about a product, if they click on of these links, and then move off to another page, then the information about what product name they clicked on would follow them to that new page, and then the same thing happens on the new page, if they click on one of those links again, then new info will be added to existing information, and passed on to whatever new page they visit.

I guess you could say that it works almost exactly like a shopping cart, whereby if a user Adds to Cart, their Cart, and all data inside it follows them right to Checkout.

I'd appreciate any help at all?

Thanks!

+2  A: 

Hello, what you are looking for is php sessions.

greg0ire
Hello, thanks for that. :)
lucifer
+3  A: 

You could store the data in a session, or even in a database table (if there truly is "no limit").

For more information on sessions, see Session Handling in the PHP online docs.

Justin Ethier
Well, there **is** a limit, but a very big one, there are over 740, 000 products. Thanks for the advice!
lucifer
+4  A: 

You are looking for sessions. With the limitation that you shouldn't be storing unlimited amounts of data in a session file, either; better create a temporary file that is named after the session ID, or store the data in a database.

Alternatively, you can also implement a custom session handler.

Either way, Sessions are the standard way of persisting state across page requests for the same user.

Pekka
Hey Pekka, thanks for the answer. Is it a possibility to delete session data from the database when the session is "Closed"?
lucifer
@lucifer yes, but you'd have to [register a custom session handler to do it](http://www.php.net/manual/en/function.session-set-save-handler.php). Either that, or frequently run a script that removes data tied to sessions that have timed out in the meantime
Pekka
+2  A: 

I think you really want to use a database for this purpose. Each page pulls the data out of the database as the user clicks through. I guarantee you that for a hundred or so objects from the database, the time to access the database from each new page is an order of magnitude smaller than the round trip HTTP time from the user's browser.

codeboy2k
I tend to use the $_SESSION variable for smaller things like handles to the database for this session. I don't actually like to store too much in the session itself.
codeboy2k
Ah, I get it. So when they hit the final page, I can just pull the junk from the database that corresponds to their current session? Thanks for the info! :)
lucifer
A: 

Yes, for your purpose you should use sessions, I'm agree with others users.

But keep in mind that: sessions expire. If you were looking for a persistent solution, you can store your PHP objects (vars, array, object instances, etc...) using the serialization and unserialization. Using this method you can store your objects in plain text everywhere (eg. DBMS) and restore them at any time. If you're working with objects you can also use the magic methods __sleep() and __wake().

Fabio M.