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: cookie help

  1. #1
    Senior Coder
    Join Date
    May 2004
    Posts
    1,441
    Thanks
    15
    Thanked 0 Times in 0 Posts

    cookie help

    I have the following code for setting cookies

    PHP Code:
    <?php
    setcookie
    ("username""me"time()+3600);
    setcookie("password""test"time()+3600);

    echo 
    "set cookies:";

    ?>
    and for reading cookies:

    PHP Code:
    <?php
    echo "cookies:";
    echo 
    "<br>username:".$_cookie["username"];
    echo 
    "<br>password:".$_cookie["password"];


    ?>
    but when I read the cookies they are showing as blank after I set them

    what am I doing wrong?

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Superglobals must be used in UPPERCASE so it'll be

    $_COOKIE["username"] not $_cookie["username"].

    You should've gotten a notice saying something like
    Notice: Undefined variable: _cookie

  • #3
    Regular Coder goughy000's Avatar
    Join Date
    Nov 2005
    Location
    England
    Posts
    415
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Nightfire View Post
    Superglobals must be used in UPPERCASE so it'll be

    $_COOKIE["username"] not $_cookie["username"].

    You should've gotten a notice saying something like
    Notice: Undefined variable: _cookie
    unless notice are turned off which they often are =]
    PHP Freelancing!
    ByteForums!
    Scriptlance.comNeed a job done quick? post it on scriptlance! OR! your a programmer? sign up and get paid for these jobs!


  •  

    Posting Permissions

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