Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Please Help

Posted on 2004-04-11
2
Medium Priority
?
243 Views
Last Modified: 2006-11-17
hello,
i need help on php. In my code on top of the pages that i use cookies i have:
ob_start("ob_gzhandler");

But i dont know what it does. If i remove that from the top of the page it gives me an error about how  info sent to browser so i cant use header and cookies. Can someone please tell me what that function does and how it helps my cookies actually?
0
Comment
Question by:farhadabas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Accepted Solution

by:
TheClickMaster earned 200 total points
ID: 10801549
ob_start("ob_gzhandler");

Will cache the output of your page until the end of the script then use gzip compression to send it to the visitor.

The way PHP works is that every time something is displayed with echo,print or other output commands or if there is HTML code pefore the start of your script, it will start to send the output to the browser.

To use cookies, PHP must send a header to the browser and this header has to be sent before it starts sending the real page.

When you use ob_start("ob_gzhandler"), PHP caches the output into a buffer before starting to send data, you can tell PHP about cookies at any time, it will simply add the info at the beggining of the buffer and when it is time to send the buffer it sends it along with the rest.

When you dont use it, there is no buffer as soon as some text is output PHP starts sending it to the browser without the cookies header (since it doesnt know about cookies). When you set cookies later it gives you a warning.

To solve the problem you must tell PHP that you will be using cookies before you do any form of output:

-Make sure there is nothing before your first <?php tag. No empty lines, no HTML, nothing.
-Dont do any output with echo,print or anything else before you have made a call to set_cookie()

0
 

Author Comment

by:farhadabas
ID: 10801599
Thanks i really appreciate it.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question