www.webdeveloper.com
Results 1 to 5 of 5

Thread: $_SESSION[$id] not working?

  1. #1
    Join Date
    Jul 2006
    Location
    Sweden
    Posts
    190

    $_SESSION[$id] not working?

    Hi,

    Isn't it possible to put a variable into $_SESSION like in the title?

    Thanks!

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,384
    Yes, it is, though it probably won't work within a double-quoted string, in which case you'll probably want to concatenate it with the rest of the string, instead (or use something like printf() or sprintf()).
    "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

  3. #3
    Join Date
    Jul 2006
    Location
    Sweden
    Posts
    190
    Thanks,

    "$id" or '$id' doesn't work, how do you mean?

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,384
    No, the array key should not be quoted if using a variable.

    My concern was whether or not the following would be "legal", but a little testing shows that it is, so that is not an issue.
    PHP Code:
    <?php
    session_start
    ();
    $id 'foo';
    $_SESSION[$id] = 'test';
    echo 
    "This is a $_SESSION[$id].";
    So at this point I don't know what your actual question/issue is without more info and/or source code.
    "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
    Jan 2011
    Location
    Canada
    Posts
    125
    I use session based logins and I've got some code here I use to automatically give the user links to his/her own files. You might find parts of it useful to you.

    PHP Code:
    <?php
        $mine 
    = ($_SESSION['user_name']);
        
    $result mysql_query("SELECT * FROM UploadedFiles WHERE username = '$mine'");
        while (
    $row mysql_fetch_array($result)){
        
        echo 
    '<h2 <a href="' $row['location'] .  '">' $row['name'] . '<br>' $row['description'] . '</a></h2><br>';
        } 
        
    ?>
    It may not be the "right" way to do it, but it does work. If it makes any difference, "location" is file location, and "name" is filename.

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