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