1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Session

Discussion in 'PHP' started by kolucoms6, Oct 11, 2011.

  1. #1
    In one file , I have

    <?php
    session_start(); // start up your PHP session!
    $_SESSION['plan'] = 'silver'; // store session data

    ?>

    In another file , which gets direct from above page , I have

    <?php
    session_start(); // start up your PHP session!
    echo "Plan0" . $_SESSION['plan'];
    $plan = $_SESSION['plan'];
    ?>

    But It doesn't DISPLAY the session value which is "plan".
     
    kolucoms6, Oct 11, 2011 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #2
    don't start the session a second time.
     
    sarahk, Oct 11, 2011 IP
  3. kolucoms6

    kolucoms6 Active Member

    Messages:
    1,198
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    75
    #3
    Ok

    But Its same...

    Now, my 2nd File content is :


    <?php
    echo "Plan0" . $_SESSION['plan'];
    $plan = $_SESSION['plan'];
    ?>
     
    kolucoms6, Oct 11, 2011 IP
  4. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #4
    I don't see anything wrong with it, other than the fact that $_SESSION['plan'] have blank value.
    session_start() must be called each time you run the PHP script if you wanna use sessions.
     
    Rainulf, Oct 11, 2011 IP
  5. kolucoms6

    kolucoms6 Active Member

    Messages:
    1,198
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    75
    #5
    $_SESSION['plan'] is blank but any reason why ? :-(
     
    kolucoms6, Oct 11, 2011 IP
  6. webshore88

    webshore88 Well-Known Member

    Messages:
    130
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    123
    #6
    First I will suggest you to make sure the value has properly inserted in session.
    If yes probably when you jump from first to second page anywhere you are resetting session value.
     
    webshore88, Oct 11, 2011 IP
  7. kolucoms6

    kolucoms6 Active Member

    Messages:
    1,198
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    75
    #7
    I didn't get you when u say PROPERLY ?

    Whats wrong with my Code ?
     
    kolucoms6, Oct 11, 2011 IP
  8. JohnnySchultz

    JohnnySchultz Peon

    Messages:
    277
    Likes Received:
    4
    Best Answers:
    7
    Trophy Points:
    0
    #8
    try to add print_r($_SESSION); on each page, you can see the data of your session and if it is passed properly..
     
    JohnnySchultz, Oct 12, 2011 IP
  9. kolucoms6

    kolucoms6 Active Member

    Messages:
    1,198
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    75
    #9
    I tried echo "Plan0" . $_SESSION['plan']; and It returned me NULL
     
    kolucoms6, Oct 12, 2011 IP
  10. HuggyEssex

    HuggyEssex Member

    Messages:
    297
    Likes Received:
    4
    Best Answers:
    2
    Trophy Points:
    45
    #10
    Try a simple test to make sure your sessions are working right.

    
    session_start();
    $_SESSION['test'] = 'Session works';
    echo $_SESSION['test'];
    
    PHP:
    If you get the text 'Session works' displayed on the screen you know your session are setup right.

    Glen
     
    HuggyEssex, Oct 12, 2011 IP
  11. webshore88

    webshore88 Well-Known Member

    Messages:
    130
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    123
    #11
    "PROPERLY" sense, make sure whatever have you inserted in session, has saved in it.
    you can var_dump($_SESSION['plan']) after inserting any value in it. if find any confusion query me again!!!
     
    webshore88, Oct 12, 2011 IP
  12. AliceWonder

    AliceWonder Peon

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Is your cookie being sent from your browser?
     
    AliceWonder, Oct 12, 2011 IP
  13. kolucoms6

    kolucoms6 Active Member

    Messages:
    1,198
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    75
    #13
    HuggyEssex , It works

    webshore88 , I tried echo and It works !!

    AliceWonder , cookie being sent ? Means ?
     
    kolucoms6, Oct 12, 2011 IP
  14. AliceWonder

    AliceWonder Peon

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #14
    HTML is stateless.

    When you start a session, the session is stored according to a session ID. This session id is then referenced in a cookie sent to your browser. Next time your browser connects to web site, it sends the cookie as part of its connection headers so that the web site knows the connection is coming from the user associated with the session.

    If your browser is configured to reject cookies or reject cookies from the domain you are using, sessions won't work unless passes as GET variables (which is very insecure and should not be done).

    In your browser preferences, you should be able to see what the settings are with respect to cookies, and whether or not your browser is accepting them.

    Some over zealous virus protection software interferes with cookies because cookies can be used to track users.
     
    AliceWonder, Oct 12, 2011 IP
  15. kolucoms6

    kolucoms6 Active Member

    Messages:
    1,198
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    75
    #15
    I checked and found my Cookies are NOT disabled !!!
     
    kolucoms6, Oct 12, 2011 IP
  16. HuggyEssex

    HuggyEssex Member

    Messages:
    297
    Likes Received:
    4
    Best Answers:
    2
    Trophy Points:
    45
    #16
    Create these pages.
    index.php
    
    <?php
    session_start();
    $_SESSION['test'] = 'The sessions are working fine.';
    echo '<a href="view.php">Check session has been made</a>';
    ?>
    
    PHP:
    view.php
    
    <?php
    session_start();
    if(isset($_SESSION['test'])) {
    echo $_SESSION['test'];
    }else{
    echo 'Sessions are not working.';
    }
    ?>
    
    PHP:
    You need to go to index.php first, then after click the link which will take you to the second script. Just create these 2 files don't place any HTML around them, the most likely issue you have here is that you are sending something to the browser before the session is started. Just try what I said and let me know.
     
    HuggyEssex, Oct 13, 2011 IP
  17. kolucoms6

    kolucoms6 Active Member

    Messages:
    1,198
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    75
    #17
    Index.php:

    Check session has been made

    view.php:

    The sessions are working fine.






    Here are My files :

    File1.php: this file calls file2.php

    File2.php:

     
    kolucoms6, Oct 13, 2011 IP
  18. HuggyEssex

    HuggyEssex Member

    Messages:
    297
    Likes Received:
    4
    Best Answers:
    2
    Trophy Points:
    45
    #18
    Make this the new file2.php and let me know what it says.

    
    <?php
    session_start(); // start up your PHP session! 
    if(session_id()){
    echo "Session started!";
    }else{
    echo "Session not started!";
    }
    
    
    $plan = $_SESSION['plan'];
    
    var_dump($plan);
    exit(0);
    
    $PlanPrevValue='0';
    $PlanValue = '0' ;
    $PlanDuration='0';
    
    If ($plan == 'silver')
    {
    $PlanPrevValue='89.00';
    $PlanValue = '59.00' ;
    $PlanDuration =' 6 months ';
    session_destroy();
    }
    ElseIf ($plan == 'gold')
    {
    $PlanPrevValue='199.00';
    $PlanValue = '149.00' ;
    $PlanDuration =' 12 months ';
    session_destroy();
    }
    ElseIf ($plan == 'diamond')
    {
    $PlanPrevValue='299.00';
    $PlanValue = '249.00' ;
    $PlanDuration =' 24 months ';
    session_destroy();
    }
    elseIf ($plan == 'platinum')
    {
    $PlanPrevValue='299.00';
    $PlanValue = '349.00' ;
    $PlanDuration =' 36 months ';
    session_destroy();
    }
    else
    {
    $PlanPrevValue='0';
    $PlanValue = '0' ;
    $PlanDuration =' ';
    session_destroy();
    }
    ?>
    
    PHP:
     
    HuggyEssex, Oct 13, 2011 IP
  19. kolucoms6

    kolucoms6 Active Member

    Messages:
    1,198
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    75
    #19
    Output is :
    --------------------

    Session started!NULL
     
    kolucoms6, Oct 13, 2011 IP
  20. kolucoms6

    kolucoms6 Active Member

    Messages:
    1,198
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    75
    #20
    Any advice ??
     
    kolucoms6, Oct 13, 2011 IP