Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Please Help

Posted on 2004-04-11
2
Medium Priority
?
245 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 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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 count occurrences of each item in an array.
Suggested Courses

772 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