What are the pros and cons of storing data in:
- Hidden input fields
- Cookies/local storage
- Server side sessions
What are the pros and cons of storing data in:
Those three are not mutually exclusive things.
A hidden input is just HTML sent to the client. It does not appear on the page to the end-user, but it is entirely accessible to the client. Meaning that the user can see it (just as they can see any HTTP response from your server) by using the View Source feature in their browser.
A cookie is just another HTTP header consisting of a cookie name/value pair, that can be sent back and forth between the client and server in every request/response. This is also visible to the end-user by checking the HTTP headers from their browser's developer tools.
The term session, on its own, is dubious, because there can be client-side sessions (stored in the client's browser like with HTML5 Sessions) or it can be a server-side session.
In PHP, the session functions that you're probably referring to store the session data on the server, but send only an identifier to the client that is associated with their session. This is the session_id
that is usually sent back to the client as a cookie.
All three of these things typically work together in conjunction to do various things. So asking, which is better, is like asking which part of my car is better; the engine, the wheels, or the steering column?
In order to know how something is better you must be able to relate it to something else. Otherwise, the question makes no sense.
If you're asking when it would be appropriate to use things and for what then the answer depends on what your needs are.
When the question changes from "which is better" to "what are the uses of each" the answers generally start to become a lot more meaningful, because you will more than likely use all of them.