views:

15

answers:

1

Hi,

I am trying to use session_set_save_handler to allow me to save sessions within a mySQL database using the code below.

Everytime I try to load the page I recieve an Application Error regarding the httpd.exe, as demonstrated by the image below.

http://i48.tinypic.com/2i9l2ip.jpg

if I remove the following line the page works fine.

session_set_save_handler("sess_open", "sess_close", "sess_read", "sess_write", "sess_destroy", "sess_gc");

I am guessing that this means that I have an error somewhere in the my code but I can't see anything. Any help would be much appreciated, thanks.

function sess_open($sess_path, $sess_name) {
 return true;
}

function sess_close() {
 return true;
}

function sess_read($sess_id) {
 $result = dbQuery("SELECT data FROM sessions WHERE id = '$sess_id';");
 if (!mysqli_num_rows($result)) {
 $CurrentTime = time();
 $result = dbQuery("INSERT INTO sessions (id, access) VALUES ('$sess_id', '$CurrentTime');");
 return '';
 } else {
 extract(mysqli_fetch_array($result), EXTR_PREFIX_ALL, 'sess');
 $result = dbQuery("UPDATE sessions SET access = '$CurrentTime' WHERE id = '$sess_id';");
 return $sess_data;
 }
}

function sess_write($sess_id, $data) {
 $CurrentTime = time();
 $result = dbQuery("UPDATE sessions SET data = '$data', access = '$CurrentTime' WHERE id = '$sess_id';");
 return true;
}

function sess_destroy($sess_id) {
 $result = dbQuery("DELETE FROM sessions WHERE id = '$sess_id';");
 return true;
}

function sess_gc($sess_maxlifetime) {
 $CurrentTime = time();
 $result = dbQuery("DELETE FROM sessions WHERE access + $sess_maxlifetime < $CurrentTime;");
 return true;
}

session_set_save_handler("sess_open", "sess_close", "sess_read", "sess_write", "sess_destroy", "sess_gc");
session_start();
A: 

That is a bug in the httpd, not in your code. Or, rather, it is surely caused by your code, but apache shoud never crash like that (you should get PHP errors, while here it is just crashing the server). Try updating wamp, or try to install xampp and check if you can get a more meaningful error.

Palantir
Thanks, I have installed XAMPP and it worked straight away!!! Not sure what the problem was with WAMP but will stick to XAMPP from now.Seems to run faster aswell as I have always found WAMP to be a little slow especially with mySQL connections, not sure wether that's just my set up.
Anthony
It's common to find problems with those services. I use them for development all the time, but If you wish to have a really serious PHP setup on windows, you should probably resort to IIS, which has a (quite good) PHP hosting facility on newer versions (IIS7 up). Or, you should install a virtual machine with linux.
Palantir
By the way: if this answer was helpful, you should accept it (click on the V sign here on the left) or at least upvote it (press the up arrow). It's the way to say "thank you" and to say that your question has been answered.
Palantir