I work in a website and we need to cluster server to have more than 1 computer handling with traffic. so I need to convert php session (file session) to a db for this cluster work.
I have a simple login file: check if post user == password, if num rows == 1:
$_SESSION['user']=$_POST['user'];
my problem starts here, how can I write this USER in my database using session_set_save_handler? what I need to change get _write work?
public function _write($id){
// Create time stamp
$data = time();
// Set query
$this->db->query('INSERT INTO sessions (id,user,data) VALUES (:id, :user, :data)');
// Bind data
$this->db->bind(':id', $id);
$this->db->bind(':user', $user); //how can i get login user?
$this->db->bind(':data', $data);
// Attempt Execution
// If successful
if($this->db->execute()){
// Return True
return true;
}
// Return False
return false;
}
DB
CREATE TABLE IF NOT EXISTS `sessions` (
`id` varchar(32) NOT NULL,
`user` varchar(20),
`data` text,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;