Solved

Please Help

Posted on 2004-04-11
2
211 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
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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

831 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