$_Session or mysqli_query

Hi

I have a general question. I can either pass variables between scripts with $_Session variable for PHP or ping the server each time.

What are some points to consider when debating between the two approaches?

Thanks!

You store data in the database that you want to keep even after the end of the session.
You use session variables for data that you don’t want to keep after the end of the session.

Sure but I’m thinking about speed vs security - if I store in a session once I retrieve the data from the database I don’t really have to make that query again and can just pass the value between scripts.

Or perhaps querying the database again is safer or faster?

I think it’s normal to do something like that, in for example a login system, so when a user logs in, some of their data gets pulled from the database and saved in a session where it can be accessed for the duration.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.