Sesion Variable losing data help please

Discussion in 'PHP' started by PinoyIto, Sep 28, 2012.

  1. #1
    Please help, I can't figure out why the value of session save in one page is lose when I tried to access in other page...

    E.g

    AT login.php

          $_SESSION['username'] =$_POST[login];
    			 $_SESSION['password'] =$_POST[password];
    
                         
    Code (markup):
    now on logs.php

      echo $_SESSION['username'] ; 
    Code (markup):

    value of the session variable is not showing.
     
    PinoyIto, Sep 28, 2012 IP
  2. plussy

    plussy Peon

    Messages:
    152
    Likes Received:
    5
    Best Answers:
    9
    Trophy Points:
    0
    #2
    remember to put a session_start(); at the top of login.php and logs.php. If you don't do it then yes the session will be lost.
     
    plussy, Sep 28, 2012 IP
  3. Sitesupplier

    Sitesupplier Peon

    Messages:
    16
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    0
    #3
    It may also be worthwhile using some debug code to help you figure out whether or not your session is even being set in the first place. You could use something like:

    
    <pre>
    <?php 
        echo "SESSION: <br />"; print_r($_SESSION); 
        echo "POST: <br />"; print_r($_POST);
        echo "GET: <br />"; print_r($_GET); 
    ?>
    </pre>
    
    Code (markup):
     
    Sitesupplier, Sep 28, 2012 IP
  4. PinoyIto

    PinoyIto Notable Member

    Messages:
    5,863
    Likes Received:
    170
    Best Answers:
    0
    Trophy Points:
    260
    #4
    Yes... I put session_start function but still the value of the session variable lose
     
    PinoyIto, Oct 5, 2012 IP
  5. Vick.Kumar

    Vick.Kumar Active Member

    Messages:
    138
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    90
    #5
    Hi,

    Could you post a bit more code, so we can analyze it further?
     
    Vick.Kumar, Oct 5, 2012 IP