www.webdeveloper.com
Results 1 to 5 of 5

Thread: echo everything in session

  1. #1
    Join Date
    Apr 2005
    Location
    Vancouver, BC
    Posts
    129

    echo everything in session

    How would I go about printing everything that's currently displayed in the session, without knowing ahead of time what's stored in the session. Just for debugging purposes I want everything in the session and it's values displayed at top of page at all time.

  2. #2
    Join Date
    Oct 2005
    Posts
    843
    This will echo all the values stored in the session.
    PHP Code:
    foreach($_SESSION as $value){
        echo 
    $value;

    So if you have:
    PHP Code:
    <?php

    session_start
    ();

    $_SESSION['test1'] = "test 1";
    $_SESSION['test2'] = "test 2";
    $_SESSION['test3'] = "test 3";

    foreach(
    $_SESSION as $value){
        echo 
    $value " | ";
    }
    ?>
    It will display:
    Code:
    test 1 | test 2 | test 3 |

  3. #3
    Join Date
    Nov 2008
    Posts
    2,477
    I tend to do this since it formats it nicely:

    PHP Code:
    echo sprintf("<pre>%s</pre>"print_r($_SESSIONtrue)); 

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,604
    Quote Originally Posted by Mindzai View Post
    I tend to do this since it formats it nicely:

    PHP Code:
    echo sprintf("<pre>%s</pre>"print_r($_SESSIONtrue)); 
    You could save yourself a bit of typing by using printf() and losing the echo.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Nov 2008
    Posts
    2,477
    Thanks, I use echo sprintf out of (bad!) habit, I'll have to bear printf in mind.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles