Web Analytics Made Easy -
StatCounter sessions - CodingForum

Announcement

Collapse
No announcement yet.

sessions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • sessions

    oh....one other thing

    how is the session variable carried to another page and how do you print the session variable on another page?


    like...lets say i wanted to store a username into a session

    ok lets say you type in your username here and submit it...
    (lets call this page submit.php)


    PHP Code:
    <?php
    session_start
    ();
    ?>
    <html>
             <body>
    <form method="post" action="login.php">
    <input type="text" name="username">
    <input type="submit" value="login">
    </form>
             <body>
    </html>
    now this is where it send the form data when u click submit...

    (lets say the below code is in a file called login.php)



    PHP Code:
    <?php
    session_start
    ();
    ?>
    <html>
              <body>
    <?php

    $username  
    =  $username1."".$username."";

    $_SESSION['sessionusername'] = $username;

    print  
    "<input type=\"text\" name=\"username\" value=\"$sessionusername\">";

    ?>
              <body>
    </html>


    so i just threw that togethor right quick but anyway. as youc an see what im trying to do is store the username in a session thatway whenever a page requests the username what their entered before is in a session and it puts the value of the session variable in the value for the input box of the username input box..

    sorry if this is confusing but thanks
    ~Designer's Toolz~

  • #2
    All you need to do is just start the session as you have done. Then store the value in the session almost as you have done. Need to use the proper method of grabbing POST or GET data.

    PHP Code:

    <?php
    session_start
    ();
    $_SESSION['sessionusername'] = $_POST['username'];
    ?>

    <html>
              <body>

    <input type="text" name="username" value="<?php echo $_SESSION['sessionusername']; ?>">

              <body>
    </html>
    Last edited by Spookster; Feb 11, 2004, 04:46 PM.
    Spookster
    CodingForum Supreme Overlord
    All Hail Spookster

    Comment


    • #3
      PHP Code:
      ...
      print 
      $_session["sessionusername"];
      ... 

      Comment

      Working...
      X