//Below is the write function from a session handler class i created for a custom site: //This allows tracking of logged in users, logging recently viewed pages and who's online/offline function write ($session_id, $session_data) { $ret = @$this->sql->query ("SELECT * FROM `{$this->table}` WHERE `SESSION_ID` = '$session_id' LIMIT 1", true, $this->db); $expire = $this->now + $this->sessionLifetime; $arr_data = array ( 'SESSION_DATA' => $session_data, 'SESSION_EXPIRE' => $expire, ); global $track; if ($ret) { @$this->sql->arr_update ($this->table, $arr_data, 'SESSION_ID', $session_id, $this->db); if (@$this->sql->affected_rows ()) { if ($ret['LOGIN_ID']) @$track->last_seen ($ret['LOGIN_ID'], $ret['LOGIN_TYPE']); return true; } } else { $arr_data['SESSION_ID'] = $session_id; $arr_data['LOGIN_TYPE'] = $_SESSION['LOGIN']['TYPE']; $arr_data['LOGIN_ID'] = $_SESSION['LOGIN']['ID']; @$this->sql->arr_insert ($this->table, $arr_data, $this->db); if (@$this->sql->affected_rows ()) { if ($_SESSION['LOGIN']['ID']) @$track->last_seen ($_SESSION['LOGIN']['ID'], $_SESSION['LOGIN']['TYPE']); return true; } } return false; } //Below is a simple array inserting function for MySQL: //This will take the array of fields and values, and place it into a query sent to the database server function arr_insert($tbl, $arr, $db='', $escape=false) { $str_q_left = "INSERT INTO $tbl ("; $str_q_mid = ') VALUES ('; $str_q_right = ')'; end($arr); $last_key=key($arr); foreach ($arr as $key => $elem) { $str_q_left .= "`$key`"; $str_q_mid .= ($escape || (substr($elem, 0, 1)!='\'' && substr($elem, -1)!='\'')) ? "'$elem'" : $elem; if ($key!=$last_key){ $str_q_left .= ', '; $str_q_mid .= ', '; } } $str_q = $str_q_left . $str_q_mid . $str_q_right; return $this->query($str_q, false, $db); }