Jump to content

Sessions and cookies


NoDoze

Recommended Posts

Is it possible and/or bad to have both of these at the same time on a website?

 

I have cookies just to maintain username and password for a 30 day period.

Then have the other user info saved in a session, then deleted when they close their browser.

Is that ok?

 

I also have these sessions validated via a mysql database of user info.

 

Or am I thourougly confused....?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/56598-sessions-and-cookies/
Share on other sites

ok, this is cool....really helped alot...but I have another questions....it got me thinking :)

 

As above:

if ($_SESSION['logged'] == "true" || $_COOKIE['logged'] == "true")

...is an or statement...

 

But I want to varify that the user has BOTH a cookie AND a session loged in the mysql database...

 

Then depending on what they don't have, send them to the appropraite login page.

 

Possible?

 

Some sort of if, then, else statement, but in my head it becomes a convoluted mess...HELP!

 

Thanks!

 

Link to comment
https://forums.phpfreaks.com/topic/56598-sessions-and-cookies/#findComment-282430
Share on other sites

I would really store the username and password (password md5'ed of course) in the session and or cookie and check against that each page load.

 

Having a single variable "logged" as set to true, it is alot easier to spoof that than to spoof someone's password via an md5 hash.

 

My 2 cents is stay away from the easy spoof and validate the user's information against the DB on each page call.

 

If you want to verify they have both this would suffice

 

<?php
if (isset($_SESSION['logged']) &&  isset($_COOKIE['logged']))

 

Would probably work better. But as I stated before, I prefer to check the user credentials each page call for tighter security.

Link to comment
https://forums.phpfreaks.com/topic/56598-sessions-and-cookies/#findComment-283497
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.