July 8, 201115 yr hi all require 'sessions/sessions.php'; session_set_save_handler('_open' , '_close' , '_read' , '_write' , '_destroy' , '_garbage'); session_start(); ?> dose not seem to be putting the sessions in to a db why any ideas
July 8, 201115 yr hi all require 'sessions/sessions.php'; session_set_save_handler('_open' , '_close' , '_read' , '_write' , '_destroy' , '_garbage'); session_start(); ?> dose not seem to be putting the sessions in to a db why any ideas wouldnt a session have to start before you even try and set or save handlers? also ive never seen anything like that before :s, just insert into a new row in mysql database using the sessions like variables
July 8, 201115 yr Author // session handling functions function _open() { global $_sess_db; if ($_sess_db = mysql_pconnect("localhost", SYS_USER, SYS_PASS)) return mysql_select_db(CUR_DB, $_sess_db); return FALSE; } function _close() { global $_sess_db; return mysql_close($_sess_db); } function _read($id) { global $_sess_db; if ($db_result = mysql_query("SELECT data FROM sessions WHERE id = '$id'", $_sess_db)) { if (mysql_num_rows($db_result)) { $record = mysql_fetch_assoc($db_result); return $record['data']; } } return ''; } function _write($id, $data) { global $_sess_db; $access = mysql_real_escape_string(time(), $_sess_db); $id = mysql_real_escape_string($id, $_sess_db); $data = mysql_real_escape_string($data, $_sess_db); return mysql_query("REPLACE INTO sessions VALUES ('$id', '$access', '$data')", $_sess_db); } function _destroy($id) { global $_sess_db; $id = mysql_real_escape_string($id, $_sess_db); return mysql_query("DELETE FROM sessions WHERE id = '$id'", $_sess_db); } function _garbage($max) { global $_sess_db; $old = mysql_real_escape_string(time() - $max, $_sess_db); return mysql_query("DELETE FROM sessions WHERE access < '$old'", $_sess_db); }
July 8, 201115 yr i wouldnt use that piece of crap if i were you, frankly its a bug over a bug, the author should read something about sql injection :S anyway, stupid questions: 1) do you have that database created and structure loaded? 2) SYS_USER and SYS_PASS arent set 3) any errors?
July 8, 201115 yr Author SYS_USER and SYS_PASS are set not shown there are no error codes to show and the database is set called sessions
July 8, 201115 yr SYS_USER and SYS_PASS are set not shown there are no error codes to show and the database is set called sessions hmm odd, i would create small debug function that prints a message to a file and would call at the begining of each session handler function to check if these functions are realy being executed database structure (sessions table) exists?
July 8, 201115 yr Author SQL result Host: localhost Database: saziew_wp388 Generation Time: Jul 08, 2011 at 10:58 PM Generated by: phpMyAdmin 3.3.9 / MySQL 5.5.8 SQL query: SELECT * FROM `sessions` PROCEDURE ANALYSE(); Rows: 3 Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype saziew_wp388.sessions.id NULL NULL 0 0 0 0 0.0 NULL CHAR(0) NOT NULL saziew_wp388.sessions.data NULL NULL 0 0 0 0 0.0 NULL CHAR(0) NOT NULL saziew_wp388.sessions.last_accessed NULL NULL 0 0 0 0 0.0 NULL CHAR(0) NOT NULL Edited July 8, 201115 yr by lee sands
July 8, 201115 yr at the begining index.php (or your main .php file) add: $debug = array(); in each session function add: global $debug; $debug[] = __FUNCTION__; at the end of index.php: var_dump($debug); what does it show?
July 8, 201115 yr return mysql_query("REPLACE INTO sessions VALUES ('$id', '$access', '$data')", $_sess_db); you don't have the field names in the query making the _write function return false return mysql_query("REPLACE INTO sessions (`id`,`last_accessed`,`data`) VALUES ('$id', '$access', '$data')", $_sess_db); might not fix it, but thats defo wrong
July 8, 201115 yr wouldnt a session have to start before you even try and set or save handlers? also ive never seen anything like that before :s, just insert into a new row in mysql database using the sessions like variables no, otherwise it would use its own default handlers... this helps multi-server apps use sessions cus if you have 2+ machines using file based storage then from one request to the next if you hit a different machine due to LB session stickiness settings being turned off it might not route users back to the same machine they used on the last request so the application would not be able to pick up the session and fail epically
July 9, 201115 yr at the begining index.php (or your main .php file) add: $debug = array(); in each session function add: global $debug; $debug[] = __FUNCTION__; at the end of index.php: var_dump($debug); what does it show? Would they go before and after <html> ?
July 9, 201115 yr Would they go before and after <html> ? quite simple to test it doesn't matter is the answer though <html> </html> <?php $debug = array(); global $debug; $debug[] = 'test'; var_dump($debug); ?>
July 14, 201115 yr ok debug 101.... get each query to echo out... then literally run it on your database.... if the query’s all work then awesome we have knocked that out. next is to manually run each function, using var_dump() to show the result, check php manual that each is working how it should. if both of those are done and work nicely, place a die('sds'); call at the start of one function, and make some test php to trigger that function via the session functions, if you see it, move it to the end of the function just before the return and try again. work through all functions until you have tested each. Once you have done that let us know what’s up... but have you even updated the REPLACE query yet cus its wrong and you have only said you have not done it... there’s no point asking for more help if you don’t try or let people know if you tried previous suggestions... i only said it might not work as you could have other issues not that the fix supplied might not work cus the query is simply wrong just trying to be crystal clear but reading ^^ it seams a lil arsey...
July 14, 201115 yr Author sorry i am still leraning php if i gavce you the code could you help me please
July 14, 201115 yr not a problem, dude if you use skype we can talk over that? excuse my slightly harsh nature was up all night migrating a multi server cluster to rackspace so tired muchness... no excuse but true to programmer form i can be naturally slightly grumpy anyways~ as some posts of days gone by has shown i will PM you my skype Edited July 14, 201115 yr by SniderDK
Create an account or sign in to comment