Follow Me:

Wednesday 25 February 2015

Expire the session after some peiod of time by using in php.

Basically, two methods are available to destory the sessions.

   1. session_destroy()
   2. unset($_SESSION['testvaraible'])
   3. setting the time out for this session




 1.session_destroy()

     if we will call the session_destroy(), it will destroy all the SESSION variable.It is no need any other parameters.

<?php
 session_destroy();
?>

2. unset($_SESSION['testvaraible'])

       When we will call the unset() ,it will destroyed the particular variable.
    Example:
   
     
<?php 
 // Destroyed the session variable "testvaraible".
 unset($_SESSION['testvaraible']);

?>

3. setting the time out for this session

<?php

if isset($_SESSION['LAST_MINITUte_ACTIVITY']) && 
(time() - $_SESSION['LAST_MINITUte_ACTIVITY'] > 1800)) { // last request was more than 30 minutes ago session_unset(); // unset $_SESSION variable for the run-time session_destroy(); // destroy session data in storage } // update last activity time stamp $_SESSION['LAST_MINITUte_ACTIVITY'] = time(); /* You can also use an additional time stamp to regenerate the session ID periodically,to avoid attacks on sessions like session fixation: */ if (!isset($_SESSION['CREATED'])) { $_SESSION['CREATED'] = time(); } else if (time() - $_SESSION['CREATED'] > 1800) { // session started more than 30 minutes ago // change session ID for the current session // an invalidate old session ID session_regenerate_id(true); $_SESSION['CREATED'] = time(); // update creation time }

4.session.gc_maxlifetime()

   By using php ini_set session.gc_maxlifetime also we will expire the session.

<?php
 ini_set session.gc_maxlifetime
?>

 
   

Categories: , ,

32 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete
  4. This comment has been removed by a blog administrator.

    ReplyDelete
  5. This comment has been removed by a blog administrator.

    ReplyDelete
  6. This comment has been removed by a blog administrator.

    ReplyDelete
  7. This comment has been removed by a blog administrator.

    ReplyDelete
  8. This comment has been removed by a blog administrator.

    ReplyDelete
  9. This comment has been removed by a blog administrator.

    ReplyDelete
  10. This comment has been removed by a blog administrator.

    ReplyDelete
  11. This comment has been removed by a blog administrator.

    ReplyDelete
  12. This comment has been removed by a blog administrator.

    ReplyDelete
  13. This comment has been removed by a blog administrator.

    ReplyDelete
  14. This comment has been removed by a blog administrator.

    ReplyDelete
  15. This comment has been removed by a blog administrator.

    ReplyDelete
  16. This comment has been removed by a blog administrator.

    ReplyDelete
  17. This comment has been removed by a blog administrator.

    ReplyDelete
  18. This comment has been removed by a blog administrator.

    ReplyDelete
  19. This comment has been removed by a blog administrator.

    ReplyDelete
  20. This comment has been removed by a blog administrator.

    ReplyDelete
  21. This comment has been removed by a blog administrator.

    ReplyDelete
  22. This comment has been removed by a blog administrator.

    ReplyDelete
  23. This comment has been removed by a blog administrator.

    ReplyDelete
  24. This is beyond doubt a blog significant to follow. You’ve dig up a great deal to say about this topic, and so much awareness. I believe that you recognize how to construct people pay attention to what you have to pronounce, particularly with a concern that’s so vital. I am pleased to suggest this blog.

    Java training in Bangalore | Java training in Indira nagar

    Java training in Bangalore | Java training in Rajaji nagar

    Java training in Bangalore | Java training in Marathahalli

    Java training in Bangalore | Java training in Btm layout

    ReplyDelete
  25. Its really an Excellent post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog. Thanks for sharing....
    python course institute in bangalore
    python Course in bangalore
    python training institute in bangalore

    ReplyDelete
  26. I’m planning to start my blog soon, but I’m a little lost on everything. Would you suggest starting with a free platform like Word Press or go for a paid option? There are so many choices out there that I’m completely confused. Any suggestions? Thanks a lot.
    AWS Training in Marathahalli | AWS Training in Marathahalli
    AWS Amazon Web Services Training in Chennai | Best AWS Training and Certification for Solution Architect in Chennai
    Amazon Web Services Training in Chennai |Best AWS Training in Chennai

    ReplyDelete
  27. The knowledge of technology you have been sharing thorough this post is very much helpful to develop new idea. here by i also want to share this.
    Python Online certification training
    python Training institute in Chennai
    Python training institute in Bangalore

    ReplyDelete
  28. I did not Get tired of reading this posts Really Getting interest while reading each and every post. Thanks for sharing your valuable time with this Informative contents

    python training in chennai | python training in annanagar | python training in omr | python training in porur | python training in tambaram | python training in velachery

    ReplyDelete
  29. Your info is really amazing with impressive content..Excellent blog with informative concept. Really I feel happy to see this useful blog, Thanks for sharing such a nice blog..
    Android Training Institute in Chennai | Android Training Institute in anna nagar | Android Training Institute in omr | Android Training Institute in porur | Android Training Institute in tambaram | Android Training Institute in velachery

    ReplyDelete