SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2009
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Cookie Issue

    Hello

    I have a login php where I prompt the user for a userid and password.
    They then click the submit button and it forwards them to a file
    check_login.php.

    In this file I check to see if the login is valid and if so, set a cookie

    setcookie("myCookie", "True", time()+3600);

    I need this coookie to be carried forward. When the user clicks another
    link on the check_login.php page, it takes them to
    menu.php. Here I try to read the cookie:

    echo "The cookie value is ".$_COOKIE['myCookie'];

    There is no value in the cookie and I don't know what I've done wrong.

  2. #2
    messing with my mind fristi's Avatar
    Join Date
    Feb 2009
    Posts
    292
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kath View Post
    Hello

    I have a login php where I prompt the user for a userid and password.
    They then click the submit button and it forwards them to a file
    check_login.php.

    In this file I check to see if the login is valid and if so, set a cookie

    setcookie("myCookie", "True", time()+3600);

    I need this coookie to be carried forward. When the user clicks another
    link on the check_login.php page, it takes them to
    menu.php. Here I try to read the cookie:

    echo "The cookie value is ".$_COOKIE['myCookie'];

    There is no value in the cookie and I don't know what I've done wrong.
    can you try this line:

    var_dump($_COOKIE['myCookie']);

    Then you'll see if it is really empty.


    Also check if your browser is set to accept coockies.
    To PHP or to Perl, that is the question!
    (Bucket - simpletest) User

  3. #3
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    setcookie returns a bool. Is your call returning true?
    PHP Code:
    if(setcookie('myCookie''True'time()+3600)) {
      echo 
    "Cookie set";
    }
    else echo 
    "Problem setting cookie"
    Also, if your subsequent pages just look for the value 'True' in a cookie your site is going to be very insecure. The cookie could easily be spoofed. Instead you might want to store the username and password hash in the cookie and validate those on each page request.


Bookmarks

Posting Permissions

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