SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: unset session

  1. #1
    SitePoint Member
    Join Date
    Jan 2011
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    unset session

    I use sharing hosting and I am wondering how sessions works.

    For example, I use session when user submit form and when I submit data to database, I put the following lines:
    PHP Code:
    unset($_SESSION['example']);   
    unset(
    $_SESSION['example1']);   
    unset(
    $_SESSION['example2']); 
    Is that enough or is there any extra step I should do? When this session will be deleted from server?

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,189
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    You can also use session_destory() which removes all information associated with the current user session.

  3. #3
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you have to make sure you have
    session_start() at the top so you have access to the $_SESSION variables

  4. #4
    SitePoint Member
    Join Date
    Jan 2011
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SgtLegend View Post
    You can also use session_destory() which removes all information associated with the current user session.
    But this will remove all sessions, I would like to keep some sessions. I was just worried if using only unset won't spend too much resources if those session are never deleted but only unset.

  5. #5
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use a custom mysql based session handler to delete the session where data is empty:
    PHP Code:
    <?php
    function clean($max)
    {
        global 
    $_sess_db;

        
    $old time() - $max;

        
    $old mysql_real_escape_string($old);

        
    $sql "DELETE FROM sess WHERE access < '$old' or data=''";

        return 
    mysql_query($sql$_sess_db);
    }
    my mobile portal
    ghiris.ro


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •