Solved

Please Help

Posted on 2004-04-11
2
193 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
2 Comments
 
LVL 5

Accepted Solution

by:
TheClickMaster earned 50 total points
Comment Utility
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
Comment Utility
Thanks i really appreciate it.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to dynamically set the form action using jQuery.
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 …

763 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now