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: , ,

19 comments:

  1. I ever had seen this information over the blog sites; actually I am looking forward for this information. Here I had an opportunity to read, it was crystal clear keep sharing…I have an expectation about your upcoming post.
    PHP Training in Chennai|PHP Training

    ReplyDelete
  2. This technical post helps me to improve my skills set, thanks for this wonder article I expect your upcoming blog, so keep sharing...
    Regards,
    web designing classes in chennai|web design training chennai|web designing course in chennai

    ReplyDelete

  3. Thanks for posting this useful content, Good to know about new things here, Let me share this, . Hadoop training in pune

    ReplyDelete
  4. Very helpful post.Thanks for your great information! Keep sharing.
    erp in chennai

    ReplyDelete
  5. As a Web Designer I was more interested to learn the new tips and tricks in designing the website. This article has provided interesting content related to the Web Designing which made to know some useful information. At present, the web designers are having huge demand in IT industry.
    Web Designing Course in Chennai |Web Designing Training in Chennai | Web Design Course in Chennai

    ReplyDelete
  6. This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharing this information&its very useful to me...
    Android training in chennai
    Ios training in chennai

    ReplyDelete
  7. Good and Informative post... thanks for sharing your information... keep rocks.....

    Dot Net Training in chennai | Best Dot Net Training in chennai

    ReplyDelete
  8. Pretty knowledgeable post! I'm searching for some topics Google I want to see that our site link and then opened it our site all information is really good.Well done, your job was really great

    White Label Website Builder

    ReplyDelete
  9. Great blog created by you. I read your blog, its best and useful information. You have done a great work. Super blogging and keep it up.php jobs in hyderabad.

    ReplyDelete
  10. The website is looking bit flashy and it catches the visitors eyes. A design is pretty simple and a good user-friendly interface.

    Programmierung in L├╝denscheid

    ReplyDelete
  11. It’s great to come across a blog every once in a while that isn’t the same out of date rehashed material. Fantastic read.
    I’ve bookmarked your site, and I’m adding your RSS feeds to my Google account.
    selenium training in bangalore

    ReplyDelete
  12. It has been just unfathomably liberal with you to give straightforwardly what precisely numerous people would've promoted for an eBook to wind up making some money for their end, basically given that you could have attempted it in the occasion you needed.
    Java Training in Bangalore|

    ReplyDelete
  13. I believe there are many more pleasurable opportunities ahead for
    individuals that looked at your site.
    "Devops Training in Chennai"

    ReplyDelete