Sorry, I'm not sure if I understood you. How come can ob_start() work for one page but not for another page?
Main Topics
Browse All TopicsHello,
I am trying to edit a PHP script and now it started to feel tired. What I'm trying to do is setting a cookie but it was not possible because of a headers already sent error. Then, I added "obstart()" at the beginning of the page to solve the problem. It worked flawless but the problem is now I cannot delete these cookies by setting them to a prior date when users log out.
It looks like PHP totally ignores the setcookie() function. The same thing happened while creating them but was solved after adding obstart() at the start. Same trick doesn't work in my logout.php
Any ideas?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Oh you are not using ob_clear/flush in a loop somewhere?
In that case you shouldn't need ob_start()
The error usually means that you allready sent something to the browser forcing headers to be sent (as they are the first thing to go to a browser, and thats what php uses to set cookies).
Put it all the way on top of your script before anything else (even html, css and whatever).
Then it should be working.
http://www.experts-exchang
This question may help explain things further.
This is really what I do but hopelessly even setting them as a first thing on my page, it doesn't work.
I don't use flush or clear functions because simply ob_start() always worked for other related problems (but not this time though). The problem is I am using frames and what I'm editing is only a part of three separate pages. So, there is no way I can prevent others outputting (at least I don't know how to do so)
Isn't there a reason ob_start() works for one page but not for another page?
You can use sessions and cookies together. You just have to do things in the right order.
Do session_start() first.
Do ob_start() next.
Read $_COOKIE and process anything associated with the existing cookies.
If you want to "delete" a cookie, you simply use setcookie() with the cookie name, a useless value, and a date/time in the past. This is commonly done in a logout script. I will post one for you in a moment
Learning about cookies is not easy - they are not intuitive. That is because the cookies are NOT AVAILABLE to the script that sets them - only to subsequent scripts. Perhaps you have noticed that login scripts set cookies, then redirect the browser to a new page? The cookie is available on that new page.
Here is a script that teaches about how to set cookies and how to understand them. Print the code, install it on your server and run it, reading the code as you watch the script output. It should help clarify things for you.
Business Accounts
Answer for Membership
by: phpmonkeyPosted on 2009-03-14 at 05:02:14ID: 23886382
After your headers have been sent you need to reload the page to be able to use set_cookie again since it all happens in the headers.
A possible solution is to inject your page with javascript that handles everything when the page load complete's.
Though i have found this though when using output buffering.