Forum Moderators: coopster

Message Too Old, No Replies

Session and Cookie logic

defies the definition of LOGIC

         

grandpa

10:30 pm on Nov 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Would someone be kind enough to validate the logic in this code.

$sesscookie = $_COOKIE['name'];
if ($sesscookie == "") {
if (!session_id()) {
session_start();
$sess_id = session_id();
setcookie('name', $sess_id);
}
$sess_id = session_id();
}
else {
$sesscookie = session_id();
}

What I'm trying to do is ensure that I have a single session id stored somewhere - a cookie if possible, and in a database record. Assuming it is stored in a cookie, I want the cookie value NO MATTER if the actual session id is changed.

If the cookie is NOT set (some browser settings disallow this) then I'll retrieve the original value of the session_id from the database. That code is not displayed here.

coopster

12:51 pm on Nov 9, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Passing the Session ID [php.net] in PHP[/url] can use cookies, so you wouldn't have to set another cookie, you could let PHP handle that for you. Passing the Session ID in PHP can also be managed outside of using cookies by passing the special SID constant. Also, if you want more control you could have a look at the session_set_save_handler() [php.net] function.

Am I understanding your question correctly?

grandpa

1:51 am on Nov 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm not sure there was a question was :0

I'm trying to figure out session id's and cookies... of course the page is live now, which makes my mistakes even bigger. Basically I'm just trying to work thru what I know, what I think I understand, and what is right. I'll have a look at the resources you pointed to.

FWIW, right now everything seems to be working good. I had that same sense 3 days ago...

Thank You