Forum Moderators: coopster

Message Too Old, No Replies

Session - Cookie conflict?

Weird problem, can not set new session value

         

tomda

10:48 am on May 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a cookie as follow
Array ( [PHPSESSID] => 64406be254aed21f5fcaf5a2149be663 [zz_dns] => a:2:{i:0;s:1:"4";i:1;s:32:"6526523b00544c9";} )

I used the following to set the cookie

setcookie($cookie_name, serialize(array($user_id, md5($cookie_seed.$password_hash))), $expire, $cookie_path, $cookie_domain, $cookie_secure);

The fist value is I guess the session_id given by the server and the second value is an array (user_id, encrypted password, expiration time, path, domain, secure).
Everytime a page is called, I decrypt the password and check that password and user_id match. If not, I reset the cookie as "Guest".

Everything works fine.

*****************************
Then, I have the SESSION where I store few extra infos.
Everything works great except for the example below.

I have advance forms where users can upload pictures for example and I use HTTP_REFERER to a URL in the session to show a friendly "back to the page you came from" link after the form is submitted.

if(isset($_SERVER["HTTP_REFERER"])) {$_SESSION['back_url']=$_SERVER["HTTP_REFERER"];}

And it doesn't work. I can not see the back_url in the session, neither in the cookie... But it exists since $_SESSION['back_url'] give me the link.

I can only guess that the problem is related to the cookie since it was working perfectly before cookie was implemented. Anything wrong?
Thank you

eelixduppy

11:04 am on May 23, 2006 (gmt 0)




And it doesn't work. I can not see the back_url in the session, neither in the cookie... But it exists since $_SESSION['back_url'] give me the link.

I'm not exactly sure what your issue is here. Are you sure that you used session_start [us2.php.net] before you tried to set the session variable?

Also, adding error_reporting(E_ALL); [us2.php.net] to the top of the script will help identify any hidden errors.

tomda

11:30 am on May 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for your response Eelixduppy,

Yes, I used session_start() before working/checking cookie; and no hidden errors!

But I have added ob_start() at the beginning of my login/logout/register (the ones sending cookies) to remove the "Cannot modify header information" error. I was getting this error despite the fact that cookie is sent before any HTML output (neither blank space).

I hope that I am not confusing everyone with all my assumptions. To make it short, the problem is that I have difficulties to set data in $_SESSION.

eelixduppy

10:30 pm on May 23, 2006 (gmt 0)



You are using cookie and session interchangably when they aren't entirely the same, but they are very similiar. Declaring a session variable doesn't seem to be the problem, but how are you calling it? Are you using $_SESSION['back_url'] to call it?