Problem retreiving cookie

Discussion in 'PHP' started by ghostwalkz, Apr 22, 2007.

  1. #1
    I am writing a new php page and need to determine which user is logged in from the cookie ´usercookie[username]´ . I am using the following code:

    <?php
    $currentuser = $_COOKIE["usercookie[username]"];
    ?>

    But it returns nothing, any ideas, is it something to do with the square brackets that are within the cookie name?

    Thanks in advance.
     
    ghostwalkz, Apr 22, 2007 IP
  2. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #2
    $_COOKIE ['usercookie'] ?
     
    commandos, Apr 22, 2007 IP
  3. ghostwalkz

    ghostwalkz Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I know its wierd but that is the name of the cookie when I view it in firefox thats is name

    usercookie[username]
     
    ghostwalkz, Apr 22, 2007 IP
  4. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #4
    try to print all your variable content to see what's inside :

    print_r($_COOKIE);
     
    commandos, Apr 22, 2007 IP
  5. Aragorn

    Aragorn Peon

    Messages:
    1,491
    Likes Received:
    72
    Best Answers:
    1
    Trophy Points:
    0
    #5
    Try this,
    $currentuser = $_COOKIE["usercookie['username']"];
    Code (markup):
    If it doesn't work, then I think you will have to get it with two steps. ie
    $usercookie = $_COOKIE['usercookie'];
    $username = $usercookie['username'];
    Code (markup):
     
    Aragorn, Apr 22, 2007 IP