PHP
  Home arrow PHP arrow Output Buffering
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Output Buffering
By: David Web
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    2008-09-02

    Table of Contents:
  • Output Buffering
  • Login Script
  • Code Explained
  • Further suggestions

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Output Buffering


    (Page 1 of 4 )

    Output control (or output buffering) allows you to write and execute your scripts normally but send data to the web browser at selected times. The main benefit of this system is that you can call the header(), setcookie() and session_start() functions at any place in your scripts without having to worry about the "headers already sent" error message.

    The tools

    In our battle against the "headers already sent"error message, we are going to use several functions that are natively available to PHP:

    header()-is used to send a raw HTTP header.

    Syntax-( string $string [, bool $replace [, int $http_response_code]] )

    setcookie() -defines a cookie to be sent along with the rest of the HTTP headers. Like other headers, cookies must be sent beforeany output from your script (this is a protocol restriction). This requires that you place calls to this function prior to any output, including <html>and <head>tags as well as any whitespace.

    Syntax- ( string $name [, string $value [, int $expire [, string $path [, string $domain [, bool $secure [, bool $httponly]]]]]] )

    session_start() -creates a session or resumes the current one based on the current session id that's being passed via a request, such as GET, POST, or a cookie.

    Syntax– session_start()

    ob_start()-This function will turn output buffering on. While output buffering is active, no output is sent from the script (other than headers). Instead, the output is stored in an internal buffer.

    Syntax– ob_start()

    ob_end_flush() -This function will send the contents of the topmost output buffer (if any) and turn this output buffer off. If you want to further process the buffer's contents you have to call ob_get_contents()before ob_end_flush()as the buffer contents are discarded after ob_end_flush()is called.

    Syntax– ob_end_flush()

    ob_end_clean() -This function discards the contents of the topmost output buffer and turns off this output buffering. If you want to further process the buffer's contents you have to call ob_get_contents()before ob_end_clean()as the buffer contents are discarded when ob_end_clean()is called.

    Syntax– ob_end_clean()

    More PHP Articles
    More By David Web


     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT