SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist
    Join Date
    Feb 2005
    Posts
    581
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can I use cookies with headers and output buffering?

    I am currently working on a CMS that uses output buffering to handle the output of the scripts. Pages are output in the order of cookies > headers > content. The headers are getting sent just fine, but for some reason I can not get the cookies to set. Can I use the header() and setcookie() functions together if I am using output buffering? I was under the impression that I could but now it does not appear so.
    I will not flame the newbies,
    I will not flame the newbies,
    I will flame the newbies...
    Table free is the way to be!

  2. #2
    SitePoint Zealot
    Join Date
    Oct 2005
    Location
    Hegelsom, The Netherlands
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you sure it's not the code that's the problem? To my knowledge, they can be combined. Can you post the code that you use to set the cookies as well as the url you're trying to do this at (that might conflict when trying to set cookies)

    Thanks in advance.
    Yeap, I'm new here :P

    Game Insight

  3. #3
    SitePoint Evangelist
    Join Date
    Feb 2005
    Posts
    581
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Unfortunately I do not currently have the internet so the application is running on a local dev box right now. Also, because I am at the library right now I do not have the code in front of me. Sorry!

    What's odd is that setcookie() is returning 1 but when I output the getallheaders() function the only cookie that shows up is PHPSESSID.
    I will not flame the newbies,
    I will not flame the newbies,
    I will flame the newbies...
    Table free is the way to be!

  4. #4
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,935
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by BluDragon
    but when I output the getallheaders() function the only cookie that shows up is PHPSESSID.
    That's not going to tell you anything because that is several steps down the chain. The cookie is probably not set because the browser rejects it due to incomplete information. Post your cookie code!

  5. #5
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    Brooklyn, NY
    Posts
    359
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by BluDragon
    Unfortunately I do not currently have the internet
    Sorry, I borrowed it. I'll give it back in a minute. :-)

    Quote Originally Posted by BluDragon
    What's odd is that setcookie() is returning 1 but when I output the getallheaders() function the only cookie that shows up is PHPSESSID.
    Well, that's a poor test. When you use header() or setcookie(), you're setting HTTP response headers - headers that will be sent in the response. The getallheaders() functions shows you what HTTP headers were included in the request. These are two entirely different things.

    Once you have access to your code, post the relevant portions here. I'm sure it's something simple.
    Chris Shiflett
    http://shiflett.org/


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
  •