Forum Moderators: coopster

Message Too Old, No Replies

Loosing your sessions using PHP and MySQL

If it can help someone

         

tata668

4:02 am on Jun 14, 2005 (gmt 0)

10+ Year Member



I found a bug in my application and it took me a lot of time to figure out what it was, so if it can help someone...

I was loosing my sessions from time to time, my users were just logged off for a reason I wasn't able to explain.

I'm using a custom session handler to save the session in MySQL. In fact I used this code:
[zend.com...]

Why I was loosing my sessions?
Because of the "ses_value text" field in the DB! My data sometimes exceeded 65535 bytes so the value saved in the DB was truncated! Therefore my sessions weren't loaded correctly after that.

I changed the field type to "mediumtext", which is way bigger, and now everything is fine!

More informations about types limits:
[dev.mysql.com...]

Hope it helps someone because it took me hours to figure out that bug!

ekram

6:07 am on Jun 14, 2005 (gmt 0)

10+ Year Member



Thanks for your post.
it's really help me.

tomda

7:16 am on Jun 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Tata,

This sounds very interesting. I will try to implement to find out how it works.

Nonetheless, do you mind give me some tips. I am new to class so I struggle a little bit.

Could you show how you add a variable in the session for example?

Thx

tata668

2:11 pm on Jun 14, 2005 (gmt 0)

10+ Year Member



ekram:
I'm happy if that helped you!

tomda:
Look at the zend URL I gave in my message: there is a "Sample" section that will show you how to use the code. What you have to remember is that once the custom session handler is properly written, you can forget it and use the $_SESSION variable like you would do with the defaut session handler. Really easy.