Jump to content

random session data not being inserted into table


kcp4911

Recommended Posts

Hello.

 

I have a couple of different scripts that incorporate storing session data into a mysql table.

 

let me use an example...

 

I have a simple message board. When making a comment I store the user id, the thread id, the comment, the ip address and a timestamp in a table. Obviously the record is given an id as well.

 

Now, this works nicely 99% of the time.

 

However, one user could make 5 different comments on the board in one session. Four of those comments would be recorded perfectly - but the other one would record everything except the user id (which is stored in a session).

 

What could make this happen?

 

is it a server issue? Is it a mysql issue? Is it a php issue?  :confused:

 

I am inclined to think it is a server issue.

 

Thanks for having a think about it.

 

simon

You have two apparent problems -

 

1) Your form processing code is not checking if the current visitor that submitted data to the form processing code is logged in, and

2) Your sessions are ending while a visitor is entering information in the form.

 

The fix for item #1 is obvious. The fix for item #2 is to set session.gc_maxlifetime to a longer value and if you are on shared web hosting and are using the default session.save_path setting you will also need to set the session.save_path setting to be to a folder within your account's folder tree so that only your session settings apply to your sessions. All session settings just mentioned need to be set before every session_start() statement, so it is best to globally set them in the master php.ini (when you have access to it), in a local php.ini (when php is running as a CGI application), in a .htaccess file (when php is running as an Apache Module), or in your script.

Also, fix #2 will take care of the case where someone on a shared web server has intentionally used a short session.gc_maxlifetime (in a misguided attempt to log people out after a short period of inactivity) and it is randomly causing the sessions for your visitors to be deleted.

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.