Solved

Please Help

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

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.
This article discusses how to create an extensible mechanism for linked drop downs.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

617 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