Results 1 to 8 of 8

Thread: Sessions

  1. #1
    Join Date
    Jan 2007
    Location
    The stage
    Posts
    568
    Thanks
    23
    Thanked 6 Times in 6 Posts

    Default Sessions

    I am trying to understand how Sessions possibly work and what makes them work.
    I am trying to make a control panel, but I have one problem. When I go from the index to the account options, the information doesn't send over.

    I have 5 pages in my user control panel.
    1. Index
    2. Account Options
    3a. Upload File Form
    3b. Upload File Actions
    4. Video Options.

    I don't get how sessions work... I know they can store variables throughout multiple pages...
    I have already done the following tutorials...
    w3schools
    tengiz *or whatever it is*
    php.net
    and phpfreaks

    I am trying to have it so that a logged in user on index.php can click on upload video link and then it would carry either the username or the user id in a variable.
    Thanks

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Do you have session_start() at the top of every page? If so, how are you assigning and then calling the session variables? (post a code snippet or something). Those are the only things I can think of.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Jan 2007
    Location
    The stage
    Posts
    568
    Thanks
    23
    Thanked 6 Times in 6 Posts

    Default

    well, the thing is, I know that i need session_start() at the top... I just don't know how to get it so that I don't have to receive the variables all the time... Or do i just place session_start() at the top and all the variables carry over???

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    well, you have to have session_start at the top of the pages so that the session variables get carried over. Then to use that variable, you have to call it like so:

    Code:
    <?php
     session_start();
     echo $_SESSION['variable'];
    ?>
    hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. #5
    Join Date
    Jan 2007
    Location
    The stage
    Posts
    568
    Thanks
    23
    Thanked 6 Times in 6 Posts

    Default

    Ok i have this...
    Code:
    <?php
     session_start();
     $variable = "Var";
     $_SESSION['variable'];
    ?>
    <html>
    <body>
    <?php
    echo $variable;
    echo "<a href='end.php'>Next</a>";
    
    ?>
    </body>
    Then on the next page I have this...
    Code:
    <html>
    <body>
    <?php
    echo $variable;
    ?>
    </body>
    </html>
    It doesn't seem to be working...

  6. #6
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    This:

    Code:
     $variable = "Var";
     $_SESSION['variable'];
    is assigning the variable $variable the value of "Var" and assigning a blank value to the session variable "variable". What you need to do is the following:

    Code:
    <?php
     session_start();
     $_SESSION['variable'] = 'Var';
    ?>
    <html>
    <body>
    <?php
    echo $_SESSION['variable'];
    echo "<a href='end.php'>Next</a>";
    
    ?>
    </body>
    Then, call the same thing (the echo $_SESSION... part) on the next page.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    $_SESSION is just like $_GET and $_POST and $_COOKIE (except that you can store values to it as well). It will do absolutely nothing to standard variables, and the aray itself will be available. Actually use $_SESSION['specificitem'] every time you want to use it, for storing, and for retrieving.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #8
    Join Date
    Jan 2007
    Location
    The stage
    Posts
    568
    Thanks
    23
    Thanked 6 Times in 6 Posts

    Default

    Thanks a lot testingsite... That clears up and is exactly what I am trying todo! Thanks!

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
  •