Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Session

  1. #1
    Regular Coder
    Join Date
    Apr 2003
    Location
    Canada, Ontario, Mississauga
    Posts
    312
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Session

    Hello,

    I went to php.net and read the section about session. I have some basic idea what is session about, but not fully understand it.

    Can someone write me a simple script on how to use session? I just want to know what are some benefits of using session.

    Thank you so much,

    Mike

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    nice simple example.

    form.php
    PHP Code:
    <?
    if(!isset($_POST['submit'])){

    // form hasn't been submitted yet, so show the form
    ?>
      <form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
        <input type="text" name="Yourname">Your name<br>
        <input type="submit" name="submit" value="Submit">
      </form>
    <?
    }else{

    // form has been submitted (the value of $submit is found)
      
    session_start();
    // add Yourname into the session
      
    $_SESSION['usersname'] = $_POST['Yourname'];

    // create a 'shortcut' to access the session
      
    $usersname $_SESSION['usersname'];
      
    // show Yourname (now known as $usersname) on the page
    echo $usersname;

    // see example of session...
    echo '<script>function nextpage(){ document.location="anypage.php";}setTimeout("nextpage()",4000);</script>';
    ?>
    anypage.php
    PHP Code:
    <?
    //page to go to anytime after the form has been submitted
    session_start();

    echo 
    $usersname;
    ?>
    I think that's right, it's all done on the fly, so knowing my luck, it won't work

  • #3
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    And here's a thread about sessions and cookies

    http://codingforums.com/showthread.p...threadid=17023


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •