setcookie() doesn't work anymore?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew Jiang
    New Member
    • Dec 2010
    • 3

    setcookie() doesn't work anymore?

    Hi. I made a website that has a login system.
    The cookies worked fine until I changed the layout.
    Could you tell me why this is happening?

    Login Code:
    setcookie("logi nuser", $username, time()+2592000) ;
    setcookie("logi npassword", $password, time()+2592000) ;

    (I tried checking my cookies, and I displaying my cookies when I logged in, but it doesn't even MAKE a cookie. So there's something wrong with the cookie-making system. I even tried another computer, and tried deleting my cookies before trying. Nothing works.)

    it's not an error because error_reporting (E_ALL); doesn't display anything.

    thanks in advance!
  • dgreenhouse
    Recognized Expert Contributor
    • May 2008
    • 250

    #2
    Ensure there's no output before executing setcookie()

    My first thought is that with your layout changes, you're now sending output before the cookie is being set. The cookie is sent with the html headers to the browser.

    setcookie() has to be executed before any output is sent. That includes carriage returns, doctypes, the html element, etc.

    Comment

    Working...