tags:

views:

31

answers:

2
$username = $_COOKIE['ID_my_site'];
    $pass = $_COOKIE['Key_my_site'];
    $firstName = $_COOKIE['firstName'];
    $lastName = $_COOKIE['lastName'];
    $active = $_COOKIE['active'];
    $email = $_COOKIE['emailAddress'];

then when using

echo "<b>Username:</b> <? " . $username . "?>";
        echo "<a href=logout.php>Logout</a>";

it doesn't print out the username.

A: 

If you're using that syntax exactly, then you haven't echoed the variable at all. Try:

echo "Username: $username"; 
echo "Logout";

I see you've edited your question. If $username is not getting populated, try outputting all of $_COOKIE to see what's in there first.

var_dump($_COOKIE);
dnagirl
Keep variables out of your string! Use `echo "Username: " . $username;` instead.
Douwe Maan
I find that the VERY slight performance hit I take on interpolating the variable is more than outweighed by the increased readability of the code. YMMV.
dnagirl
+1  A: 

I suspect that you never set $_COOKIE['ID_my_site']. You could do a print_r($_COOKIE); to see what it contains. I don't recommend using cookie like this, its against RFC. If you need to keep this information throughout the session then you should use $_SESSION. This also keeps malicious people from changing their cookie.

Rook