Allow administrators to limit the number of simultaneous sessions per user role.

Assuming the session limit is 1, if a user is logged in to a Drupal site from their work computer and they log in from their home computer, they would be forced to either log off the work computer session, or abort their new login from home.

I have used Session Limit module but its not as per my requirement,user should not be able to login if he is login in desktop he should not be able to login on tab and mobile simultaneously also not on cross browsers.

  • any reason for downvoting? – Vikram fz16 Apr 25 at 10:57
  • 2
    Questions that don't demonstrate what you've tried, and precisely where you're stuck with those attempts, tend to attract downvotes. They come across as "I want this, tell me how to do it", which is a request for a tutorial, and not something we would fulfil here – Clive Apr 25 at 11:00
  • Based on the module's description, it sounds to me that you did not set up Session Limit properly. – No Sssweat Apr 25 at 11:02
  • i dont know but it doesnt fullfill my requirement,but i have found the custom solution for it – Vikram fz16 Apr 26 at 6:37

For this i have created a custom table in drupal database,in which i am entering a user id by sql query on login and deleating table entry on logout like below .

use \Drupal\user\Entity\User;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Drupal\Core\Url;

function whishlistt_user_login(\Drupal\user\UserInterface $account) {

$roles = $account->getRoles();
$user_id = \Drupal::currentUser()->id();

if(in_array('test', $roles)){

$query_get_product_name = db_select('mydata', 'c');
$query_get_product_name->fields('c', ['uid']);
$result = $query_get_product_name->execute()->fetchAllAssoc('uid');
if(!empty($result)) {
$path = Url::fromRoute('user.logout', [], ['absolute' => TRUE])->toString();
$response = new RedirectResponse($path);
return $response->send();
else {
$connection = \Drupal::database();
$result = $connection->insert('mydata')
'uid' => $user_id,


function whishlistt_user_logout($account) {
$user_id = \Drupal::currentUser()->id();
$query = \Drupal::database()->delete('mydata');
$query->condition('uid', $user_id);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.