How to set Different Auto logout time for each user in Laravel











up vote
2
down vote

favorite
1












I have a time in mins for each one user in his profile, the user should automatically be logged out after that time.



Example:



User 1: Auto logout time => 60 Mins



User 2: Auto logout time => 120 Mins



User 3: Auto logout time => 150 Mins



So after login, user 1 should log out after 60 mins of login, user 2 after 120 mins and user 3 after 150 mins. Does anyone have any idea that how to achieve this?



I am thinking to change the session lifetime from the session.php file for every login request, but don't know it will work or Not.



Thanks in Advance.










share|improve this question


























    up vote
    2
    down vote

    favorite
    1












    I have a time in mins for each one user in his profile, the user should automatically be logged out after that time.



    Example:



    User 1: Auto logout time => 60 Mins



    User 2: Auto logout time => 120 Mins



    User 3: Auto logout time => 150 Mins



    So after login, user 1 should log out after 60 mins of login, user 2 after 120 mins and user 3 after 150 mins. Does anyone have any idea that how to achieve this?



    I am thinking to change the session lifetime from the session.php file for every login request, but don't know it will work or Not.



    Thanks in Advance.










    share|improve this question
























      up vote
      2
      down vote

      favorite
      1









      up vote
      2
      down vote

      favorite
      1






      1





      I have a time in mins for each one user in his profile, the user should automatically be logged out after that time.



      Example:



      User 1: Auto logout time => 60 Mins



      User 2: Auto logout time => 120 Mins



      User 3: Auto logout time => 150 Mins



      So after login, user 1 should log out after 60 mins of login, user 2 after 120 mins and user 3 after 150 mins. Does anyone have any idea that how to achieve this?



      I am thinking to change the session lifetime from the session.php file for every login request, but don't know it will work or Not.



      Thanks in Advance.










      share|improve this question













      I have a time in mins for each one user in his profile, the user should automatically be logged out after that time.



      Example:



      User 1: Auto logout time => 60 Mins



      User 2: Auto logout time => 120 Mins



      User 3: Auto logout time => 150 Mins



      So after login, user 1 should log out after 60 mins of login, user 2 after 120 mins and user 3 after 150 mins. Does anyone have any idea that how to achieve this?



      I am thinking to change the session lifetime from the session.php file for every login request, but don't know it will work or Not.



      Thanks in Advance.







      javascript jquery laravel laravel-5 laravel-5.2






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 9 hours ago









      Amol Rokade

      7619




      7619
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote













          For this you can use setInterval javascript function



              var timeoutSeconds = <?php echo Session::get('timeoutSeconds'); ?>
          var _idleSecondsCounter = 0;

          window.setInterval(CheckIdleTime, timeoutSeconds);

          function CheckIdleTime() {
          _idleSecondsCounter++;
          var oPanel = document.getElementById("SecondsUntilExpire");
          if (oPanel)
          oPanel.innerHTML = (IDLE_TIMEOUT - _idleSecondsCounter) + "";
          if (_idleSecondsCounter >= IDLE_TIMEOUT) {
          document.getElementById('logout-form').submit();
          }
          }


          In login controller you can set session like this



           $userCount = 1;

          $timeOutSeconds = 60 * $userCount;

          Session::put('timeoutSeconds', $timeOutSeconds);


          For Server Side



          Create a Background Job in Laravel and do a delayed dispatch after login method.



          Delayed Job Dispatch






          share|improve this answer



















          • 3




            A client side solution isn't very secure for this.
            – Rory McCrossan
            8 hours ago










          • Yes I agree with @RoryMcCrossan. If you need this in server side then I think need to add a scheduler to check whether the current user having valid session or not. If not logout
            – sanu
            8 hours ago










          • Yes @RoryMcCrossan, I agree with you it's not secure, Isn't there another way to do this?
            – Amol Rokade
            8 hours ago










          • I don't know enough about PHP/Laravel to give you a solution, but that is definitely where you need to be looking
            – Rory McCrossan
            8 hours ago










          • Ok. Thanks, Appreciate your help.
            – Amol Rokade
            8 hours ago











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371781%2fhow-to-set-different-auto-logout-time-for-each-user-in-laravel%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote













          For this you can use setInterval javascript function



              var timeoutSeconds = <?php echo Session::get('timeoutSeconds'); ?>
          var _idleSecondsCounter = 0;

          window.setInterval(CheckIdleTime, timeoutSeconds);

          function CheckIdleTime() {
          _idleSecondsCounter++;
          var oPanel = document.getElementById("SecondsUntilExpire");
          if (oPanel)
          oPanel.innerHTML = (IDLE_TIMEOUT - _idleSecondsCounter) + "";
          if (_idleSecondsCounter >= IDLE_TIMEOUT) {
          document.getElementById('logout-form').submit();
          }
          }


          In login controller you can set session like this



           $userCount = 1;

          $timeOutSeconds = 60 * $userCount;

          Session::put('timeoutSeconds', $timeOutSeconds);


          For Server Side



          Create a Background Job in Laravel and do a delayed dispatch after login method.



          Delayed Job Dispatch






          share|improve this answer



















          • 3




            A client side solution isn't very secure for this.
            – Rory McCrossan
            8 hours ago










          • Yes I agree with @RoryMcCrossan. If you need this in server side then I think need to add a scheduler to check whether the current user having valid session or not. If not logout
            – sanu
            8 hours ago










          • Yes @RoryMcCrossan, I agree with you it's not secure, Isn't there another way to do this?
            – Amol Rokade
            8 hours ago










          • I don't know enough about PHP/Laravel to give you a solution, but that is definitely where you need to be looking
            – Rory McCrossan
            8 hours ago










          • Ok. Thanks, Appreciate your help.
            – Amol Rokade
            8 hours ago















          up vote
          2
          down vote













          For this you can use setInterval javascript function



              var timeoutSeconds = <?php echo Session::get('timeoutSeconds'); ?>
          var _idleSecondsCounter = 0;

          window.setInterval(CheckIdleTime, timeoutSeconds);

          function CheckIdleTime() {
          _idleSecondsCounter++;
          var oPanel = document.getElementById("SecondsUntilExpire");
          if (oPanel)
          oPanel.innerHTML = (IDLE_TIMEOUT - _idleSecondsCounter) + "";
          if (_idleSecondsCounter >= IDLE_TIMEOUT) {
          document.getElementById('logout-form').submit();
          }
          }


          In login controller you can set session like this



           $userCount = 1;

          $timeOutSeconds = 60 * $userCount;

          Session::put('timeoutSeconds', $timeOutSeconds);


          For Server Side



          Create a Background Job in Laravel and do a delayed dispatch after login method.



          Delayed Job Dispatch






          share|improve this answer



















          • 3




            A client side solution isn't very secure for this.
            – Rory McCrossan
            8 hours ago










          • Yes I agree with @RoryMcCrossan. If you need this in server side then I think need to add a scheduler to check whether the current user having valid session or not. If not logout
            – sanu
            8 hours ago










          • Yes @RoryMcCrossan, I agree with you it's not secure, Isn't there another way to do this?
            – Amol Rokade
            8 hours ago










          • I don't know enough about PHP/Laravel to give you a solution, but that is definitely where you need to be looking
            – Rory McCrossan
            8 hours ago










          • Ok. Thanks, Appreciate your help.
            – Amol Rokade
            8 hours ago













          up vote
          2
          down vote










          up vote
          2
          down vote









          For this you can use setInterval javascript function



              var timeoutSeconds = <?php echo Session::get('timeoutSeconds'); ?>
          var _idleSecondsCounter = 0;

          window.setInterval(CheckIdleTime, timeoutSeconds);

          function CheckIdleTime() {
          _idleSecondsCounter++;
          var oPanel = document.getElementById("SecondsUntilExpire");
          if (oPanel)
          oPanel.innerHTML = (IDLE_TIMEOUT - _idleSecondsCounter) + "";
          if (_idleSecondsCounter >= IDLE_TIMEOUT) {
          document.getElementById('logout-form').submit();
          }
          }


          In login controller you can set session like this



           $userCount = 1;

          $timeOutSeconds = 60 * $userCount;

          Session::put('timeoutSeconds', $timeOutSeconds);


          For Server Side



          Create a Background Job in Laravel and do a delayed dispatch after login method.



          Delayed Job Dispatch






          share|improve this answer














          For this you can use setInterval javascript function



              var timeoutSeconds = <?php echo Session::get('timeoutSeconds'); ?>
          var _idleSecondsCounter = 0;

          window.setInterval(CheckIdleTime, timeoutSeconds);

          function CheckIdleTime() {
          _idleSecondsCounter++;
          var oPanel = document.getElementById("SecondsUntilExpire");
          if (oPanel)
          oPanel.innerHTML = (IDLE_TIMEOUT - _idleSecondsCounter) + "";
          if (_idleSecondsCounter >= IDLE_TIMEOUT) {
          document.getElementById('logout-form').submit();
          }
          }


          In login controller you can set session like this



           $userCount = 1;

          $timeOutSeconds = 60 * $userCount;

          Session::put('timeoutSeconds', $timeOutSeconds);


          For Server Side



          Create a Background Job in Laravel and do a delayed dispatch after login method.



          Delayed Job Dispatch







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 8 hours ago

























          answered 9 hours ago









          sanu

          179111




          179111








          • 3




            A client side solution isn't very secure for this.
            – Rory McCrossan
            8 hours ago










          • Yes I agree with @RoryMcCrossan. If you need this in server side then I think need to add a scheduler to check whether the current user having valid session or not. If not logout
            – sanu
            8 hours ago










          • Yes @RoryMcCrossan, I agree with you it's not secure, Isn't there another way to do this?
            – Amol Rokade
            8 hours ago










          • I don't know enough about PHP/Laravel to give you a solution, but that is definitely where you need to be looking
            – Rory McCrossan
            8 hours ago










          • Ok. Thanks, Appreciate your help.
            – Amol Rokade
            8 hours ago














          • 3




            A client side solution isn't very secure for this.
            – Rory McCrossan
            8 hours ago










          • Yes I agree with @RoryMcCrossan. If you need this in server side then I think need to add a scheduler to check whether the current user having valid session or not. If not logout
            – sanu
            8 hours ago










          • Yes @RoryMcCrossan, I agree with you it's not secure, Isn't there another way to do this?
            – Amol Rokade
            8 hours ago










          • I don't know enough about PHP/Laravel to give you a solution, but that is definitely where you need to be looking
            – Rory McCrossan
            8 hours ago










          • Ok. Thanks, Appreciate your help.
            – Amol Rokade
            8 hours ago








          3




          3




          A client side solution isn't very secure for this.
          – Rory McCrossan
          8 hours ago




          A client side solution isn't very secure for this.
          – Rory McCrossan
          8 hours ago












          Yes I agree with @RoryMcCrossan. If you need this in server side then I think need to add a scheduler to check whether the current user having valid session or not. If not logout
          – sanu
          8 hours ago




          Yes I agree with @RoryMcCrossan. If you need this in server side then I think need to add a scheduler to check whether the current user having valid session or not. If not logout
          – sanu
          8 hours ago












          Yes @RoryMcCrossan, I agree with you it's not secure, Isn't there another way to do this?
          – Amol Rokade
          8 hours ago




          Yes @RoryMcCrossan, I agree with you it's not secure, Isn't there another way to do this?
          – Amol Rokade
          8 hours ago












          I don't know enough about PHP/Laravel to give you a solution, but that is definitely where you need to be looking
          – Rory McCrossan
          8 hours ago




          I don't know enough about PHP/Laravel to give you a solution, but that is definitely where you need to be looking
          – Rory McCrossan
          8 hours ago












          Ok. Thanks, Appreciate your help.
          – Amol Rokade
          8 hours ago




          Ok. Thanks, Appreciate your help.
          – Amol Rokade
          8 hours ago


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371781%2fhow-to-set-different-auto-logout-time-for-each-user-in-laravel%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

          SQL update select statement

          'app-layout' is not a known element: how to share Component with different Modules