Cookies

Discussion in 'PHP' started by harryoxford, Sep 18, 2009.

  1. #1
    okay, im trying to make a script to login on a site, then click some links on the site and fill some forms. but after the login, it lose the cookie, says cookie not found
     
    harryoxford, Sep 18, 2009 IP
  2. dweebsonduty

    dweebsonduty Active Member

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    Digital Goods:
    1
    #2
    One problem could be that your cookies are written to www.yoursite.com and you are at yoursite.com (Or reverse). I had this problem the other day.
     
    dweebsonduty, Sep 19, 2009 IP
  3. astrazone

    astrazone Member

    Messages:
    358
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    33
    #3
    if the cookie isn't expiring its a code error. you have to be sure that its not a mistype.
     
    astrazone, Sep 19, 2009 IP
  4. phprightnow

    phprightnow Peon

    Messages:
    296
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Also make sure you send your setcookie() command before ANY output is sent, as it will generate errors and fail to set cookies. Make sure you are calling your cookie variables via the $_COOKIE array.
     
    phprightnow, Sep 19, 2009 IP
  5. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #5
    Not to mention that you shouldn't really use cookies for logins - use the $_SESSION variable instead.

    session_start(); on each page (as the very first code) and then something like:

    if (($username == $db_username) && ($password == $db_password)) {
    $_SESSION['logged_in'] = 'true'; } else { $_SESSION['logged_in'] = ''; }

    then later you check for the $_SESSION['logged_in'] variable and the value, etc.
     
    PoPSiCLe, Sep 19, 2009 IP
  6. bluebenz

    bluebenz Well-Known Member

    Messages:
    876
    Likes Received:
    9
    Best Answers:
    2
    Trophy Points:
    138
    #6
    What cookie is gone?
    all cookies including login and cart?
    if so, then check the your login scritp and/or browser setting (allow/disallow cookie).

    Does PoPSiCLe's solutions work?
     
    bluebenz, Sep 19, 2009 IP
  7. phprightnow

    phprightnow Peon

    Messages:
    296
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I understand in a matter of preference, some users prefer sessions to cookies, but why do you say that you "shouldn't really use cookies"? They are just as efficient, and many major sites still uses cookie-based login to-date.
     
    phprightnow, Sep 19, 2009 IP
  8. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #8
    premiumscripts, Sep 20, 2009 IP
  9. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #9
    PoPSiCLe, Sep 20, 2009 IP