SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Expiring session in a time limit

    Sir,
    This is my session coding.

    I have set the expiring of session as 1 minute.
    session_start();
    echo $sessid;
    echo "****************";
    echo session_id();
    echo " <html> \n";
    echo "<head> \n";
    echo "</head> \n";
    echo "<body> \n";

    $sessid = session_id();

    session_cache_limiter('private');
    $cache_limiter = session_cache_limiter();
    session_cache_expire(1);
    $cache_expire = session_cache_expire();
    echo " <a href=\"http://linuxserver/admin/src/sess/aa.pph?sessid=".$sessid."\">Click</a> \n";
    echo "</body> \n";
    echo "</html> \n";
    ?>

    But After 1 minute if i refresh the page the page is working fine.But fore me it
    should not work it should say "The session expire".
    How can i do it.
    ArunKumar

  2. #2
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Take a look at the directives session.gc_probability and session.gc_divisor in php.ini. Since you are probably viewing the page on your own development server (or on a low-activity server), the garbage collector may not be executed due to the settings in php.ini. For example, set session.gc_probability to one (1) and session.gc_divisor to two (2). Then there is a 50% chance that the garbage collector will run when a page is requested.

    Yours, Erik.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  3. #3
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sir,
    I am having session.gc_probability as 1, and there is no session.gc_divisor .
    What to do?
    Arunkumar

  4. #4
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Are you absolutely sure? If you can't find it anywhere in php.ini, add it:

    Code:
    session.gc_divisor = 2
    Yours, Erik.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  5. #5
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sir,

    I have run the program phpinfo the code was <?php phpinfo() ?> in that there was no session.gc_divisor.

    You ask me to add session_gc.divisor how can i do it.Can you please guide me.
    ArunKumar

  6. #6
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I just assumed that you have access to php.ini, sorry for that. Try placing this at the top of your pages:

    PHP Code:
    ini_set('session.gc_probability'1);
    ini_set('session.gc_divisor'2); 
    Yours, Erik.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  7. #7
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sir,
    Is i have to pass the session id to all pages.

    and when i add start_session() to top of my page the heade already send error is get by me.
    What to do it sir,
    Arun

  8. #8
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    You cannot have any output (spaces, HTML etc.) before calling session_start().

    Yours, Erik.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  9. #9
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sir My code is here

    session_start();
    include "pathfile.php";
    echo " <table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#FFFFFF\">\n";
    echo " <tr class=\"topback\">\n";
    echo " <td bgcolor=\"#FFFFFF\"><div align=\"left\"> \n";
    echo " <img src=\"".$imgpath."logo.gif\" width=\"130\" height=\"52\">\n";
    echo " </div></td>\n";
    echo " </tr>\n";
    echo " </table>\n";
    echo " <table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"adminTopNav\">\n";
    echo " <tr>\n ";
    echo " <td ><div align=\"left\"> \n";
    echo " <p>&nbsp;&nbsp;&nbsp;Welcome ".$sname."</p>\n";
    echo " </div></td>\n";
    echo " <td width=\"59%\"><div align=\"right\"></div></td>\n";
    echo " <td width=\"8%\"><div align=\"right\"><a href=\"".$pathconfig."index.htm\" style=\"text-decoration:none\">[Logout]&nbsp;&nbsp;&nbsp;</a><a href=\"".$fileconfig."index.htm\" style=\"text-decoration:none\">[Help]&nbsp;&nbsp;&nbsp;</a></div></td>\n";
    echo " </tr>\n";
    echo " </table>\n";

    echo " <table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
    echo " <tr>\n ";
    echo " <td width=\"19%\" valign=\"top\" background=\"http://linuxserver/postr/admin/img/leftcornerback.gif\"><img src=\"http://linuxserver/postr/admin/img/leftcorner.gif\"></td>\n";
    echo " <td width=\"62%\" valign=\"top\" background=\"http://linuxserver/postr/admin/img/leftcornerback.gif\">&nbsp;</td>\n";
    echo " <td height=\"64\" valign=\"top\" background=\"http://linuxserver/postr/admin/img/leftcornerback.gif\">&nbsp;</td>\n";
    echo " </tr>\n";
    echo " </table>\n ";


    Error shown is cannot send cookies header already send is comming.
    ArunKumar

  10. #10
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    And you are sure that your starting tag (<?php) is at the beginning of the file (no spaces or so before it) ?

    Yours, Erik.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  11. #11
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry eric,
    As you said that i have echo before session startes,Ya i get sessid values in next page thanks for it.

    Sir,I want to expires the page when the page is idle for 15 minute,I want to expire the session hope you get me,What should i do for it.
    Thanks in Advance,
    ArunKumar

  12. #12
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Try placing this at the top of your script (before calling session_start).

    PHP Code:
    ini_set('session.cookie_lifetime'1500); 
    Yours, Erik.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  13. #13
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SIr,
    i do it but not working my code is

    /*************aa.php******************
    <?
    ini_set('session.cookie_lifetime', 15);
    session_start();
    echo $sessid;
    echo "****************";
    echo session_id();
    echo " <html> \n";
    echo "<head> \n";
    echo "</head> \n";
    echo "<body> \n";

    $sessid = session_id();

    /*session_cache_limiter('private');
    $cache_limiter = session_cache_limiter();
    session_cache_expire(1);
    $cache_expire = session_cache_expire();*/
    echo " <a href=\"ref.php?sessid=".$sessid."\">Click</a> \n";
    echo "</body> \n";
    echo "</html> \n";
    ?>
    /******************ref.php*******************************/
    <?
    session_start();
    echo " <html> \n";
    echo "<head> \n";
    echo "</head> \n";
    echo "<body> \n";
    $session = session_id();
    echo $session;
    echo " <a href=aa.php?sessid=".$sessid.">Click</a> \n";
    echo "</body> \n";
    echo "</html> \n";
    ?>
    /**********************************************/

  14. #14
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here my pl ask me to session using data base.
    Sir please give me some idea how to do it.
    ArunKumar


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
  •