我有这个网站http://mxcounters.com/traffictack/
用户来到网站注册并登录。登录后,他们在自己的域中搜索一些搜索引擎优化评论。现在我想将每个用户的搜索单独存储到数据库中。然后我会将每个用户搜索的域显示到他们的帐户页面。
我尝试了一些最后的事件方法来存储在数据库中,但它没有那么有用,请帮助我:
$time_since = now() - $this->session->userdata('last_activity');
$interval = 300;
// Do nothing if last activity is recent
if ($time_since < $interval) return;
// Update database
$updated = $this->db
->set('last_activity', now())
->where('id', $user_id)
->update('users');
最佳答案
试试这个
在 Controller 中
$userId = $this->session->userdata('user_id');
if(empty($userId)){
redirect('login'); # this for user not logged
}
else{
$search = $this->input->post('domain');
$resut = $this->method_name->serach_domain($userId, $search);
if(!empty($resut)){
#have data. if user come here set another methods for Insert data
$this->model_name->insert_search_result(($userId, $search);
}
else{
# nodata
echo "No result found"
}
}
在模型中
function insert_search_result(($userId, $search){
$data = array(
'user_id' => $userID ,
'search' => $search,
'timestamp' => date('Y-m-d H:i:s')
);
$this->db->insert('mytable', $data);
}
关于php - 如何使用 session 将用户事件存储到数据库: Codeigniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34286589/