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 error

  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Depends on the time of year
    Posts
    478
    Thanks
    0
    Thanked 0 Times in 0 Posts

    cookie error

    just tried every single variation of setcookie I can think of, and it doesn't work. Gives me the following error:

    Warning: Cannot add header information - headers already sent by (output started at /home/location/testing.phtml:9) in /home/location/testing.phtml on line 12

    $time = time() + 30;
    $value = session_id();

    setcookie("yummycookie", $value , $time);

    Tried every single variation I could think of, and I still keep getting the same error.

    any suggestions??

    Thanks
    Duniyadnd

  • #2
    New Coder
    Join Date
    Aug 2002
    Posts
    76
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Setcookie must be the first thing in a php file. You have some output before it (line 9) and this is causing the problem.

    Taken from the php web site:

    Like other headers, cookies must be sent before any output from your script (this is a protocol restriction). This requires that you place calls to this function prior to any output, including <html> and <head> tags as well as any whitespace. If output exists prior to calling this function, setcookie() will fail and return FALSE.

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Depends on the time of year
    Posts
    478
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Gotcha, didn't know what they meant by headers when they mentioned it.

    Thanks
    Duniyadnd


  •  

    Posting Permissions

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