如果用户位于页面localhost/chat
,我想将其添加到表users_chat
,但当他在其他页面上时,例如localhost/faq
将其从users_chat
表中删除。
我有这段代码,但它不会工作:
$url = parse_url($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], PHP_URL_PATH);
if($url === 'localhost/czat'){
$uzytkownicy_on = $db->query('INSERT OR REPLACE INTO chat_users(id, login, activity) VALUES (:id, :login, :activity)', array(
':id' => $_SESSION['userid'],
':login' => $_SESSION['username'],
':activity' => date('Y-m-d H:i:s', strtotime(date('Y-m-d H:i:s')))
));
}else{
$uzytkownicy_on = $db->query('DELETE FROM chat_users WHERE id = :id', array(
':id' => $_SESSION['userid'];
));
}