Jump to content

Recommended Posts

Hello all ...

Just a question ...

I'm writing code for a site  that need authentication .

The authentication part works with a certificate installed in the browser against a mysql db .

When the user is authenticated I use sessions to pass data from one page to another , I save the session data in an array , destroy the session , create a new one and copy the data back .

This to prevent hijacking of the session .

My question is ... wouldn't be more secure to store all the data in a database instead of saving it in the session ? Or better , what are the advantages/disvantages to use session instead of using a db for this purpose ?

 

Thx in advance

 

David

 

Link to comment
https://forums.phpfreaks.com/topic/128185-sessions-vs-database/
Share on other sites

I often use fingerprints in my session. I know that it's security through obscurity, but it really does make it much harder for anyone trying to play around.

 

$_SESSION['fingerprint'] = md5($_SERVER['HTTP_USER_AGENT'].session_id()."randomLOLXD");

 

If you're on a shared server, Sessions might be the way to go. However, anyone with access to the actual physical session file probably wont be able to know what site is using it.

Link to comment
https://forums.phpfreaks.com/topic/128185-sessions-vs-database/#findComment-663879
Share on other sites

If you mean for temporary data storage. Yes, it probably would be more secure, but efficient, no.

It would be more queries then you would want and a large unnecessary load on your database.

 

You pretty much already seem to know the purpose of a session so I won't bother explaining it...so I'd just say to stick with it.

If you need the session to be secure then don't put anything in it that you don't want a "hijacker" to have.

Link to comment
https://forums.phpfreaks.com/topic/128185-sessions-vs-database/#findComment-663884
Share on other sites

Thx for you replies ...

Would be more efficient even If I destroy and re-create sessions ?

This way I write a new session on the filesystem every time , the other way I'd make queries on the db ...

Or maybe you was telling me that I should not recreate sessions ?

I saw it's possible to save sessions on the db too , with session_set_save_handler() ...

Security is very important in this case , because the web gives access to the resources of a grid of clusters .

Link to comment
https://forums.phpfreaks.com/topic/128185-sessions-vs-database/#findComment-663909
Share on other sites

thanks for you replies ...

Would be more efficient even If I destroy and re-create sessions ?

This way I write a new session on the filesystem every time , the other way I'd make queries on the db ...

Or maybe you was telling me that I should not recreate sessions ?

I saw it's possible to save sessions on the db too , with session_set_save_handler() ...

Security is very important in this case , because the web gives access to the resources of a grid of clusters .

 

Don't keep destroying and recreating the session, as it just wastes disk space until the garbage collector cleans up those dead sessions.

Link to comment
https://forums.phpfreaks.com/topic/128185-sessions-vs-database/#findComment-663923
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.