PHP session

Discussion in 'PHP' started by hansab, Sep 4, 2012.

  1. #1
    Hi,

    Let say someone visits yoursite.com / session-on.php

    then i want the whole site, no matter which php page visitor visits.... i want this on top

    session = on

    and i want it for the maximum period of time. For how long i can do that please insert that in the code you will share with me to help me

    So, the session on code will be in session-on.php

    and the <p>Session = on</p> will be added on header.php so it shows on all the pages.

    Please help if you can.

    Thanks
     
    hansab, Sep 4, 2012 IP
  2. nhl4000

    nhl4000 Well-Known Member

    Messages:
    479
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    110
    #2
    
    <?php
    session_start(); // This starts the session
    
    if(isset($_SESSION['ison'])) {
          // session is on
    } else {
       // session if off
    }
    ?>
    
    Code (markup):
    Let's say a visitors goes to the /session-on.php
    - the session key 'ison' becomes set with the value 'on'.
    
    <?php
    session_start(); // This starts the session
    $_SESSION['ison'] = "on"
    ?>
    
    Code (markup):
    For the maximum time:
    - you must set the cache expire and limiter BEFORE session_start
    
    <?php
    session_cache_limiter('private');
    session_cache_expire(90); // 90 minutes - any integer value.
    session_start();
    ?>
    
    Code (markup):
    other way is the change the max lifetime in the function init_set()
    
    <?php
    ini_set("session.gc_maxlifetime", "18000");
    session_start();
    ?>
    Code (markup):
     
    nhl4000, Sep 4, 2012 IP