gpt4 book ai didi

php - 如何使用 session : Codeigniter 将用户事件存储到数据库

转载 作者:搜寻专家 更新时间:2023-10-30 20:25:55 24 4
gpt4 key购买 nike

我有这个网站http://mxcounters.com/traffictack/

用户来到站点注册并登录。登录后,他们会在自己的域中搜索一些 seo 评论。现在我只想将每个用户搜索分别存储到数据库中。然后我会将每个用户搜索的域显示到他们的帐户页面。

我已经尝试了一些最后的事件方法来存储在数据库中但是它没有那么有用请帮助我:

       $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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com