Wednesday 19 March 2014

output buffering start function In Php

ob_start function php
Output Buffering Start in php programming language. In articles you can see Using the Header function to Force Page Redirect how we can use it to change headers we used example of relocating users to the specific page. Now we cause problem if we use to send data before header function. Header function causes error

We had warning : cannot modify header information - headers already sent by (output started at location page line ) in location page line. Now there is a simple way to resolve this and to solve this problem we will use function ob_start stands for output buffering start what does this function does is buffering on. Now let see how we can write in our program in our code then i will tell you about function and we use it.

code for Output buffering starts function

Code Output Buffering Start Function In Php




<?php ob_start(); ?>



<h1> My Page </h1>

This is my page.



<?php

$redirect_page = 'http://google.co.uk';

$redirect = false;



if ($redirect==true) {

 header('Location:'.$redirect_page);

}



ob_end_flush();

?>

Output (Screenshot2):-

Output Buffering start function in php Output Screenshot2
ob_start function will be declare top of the page. ob_start function can be called without arguments. Ob_start function will store page output on internal buffer rather then had header. In this example redirect is false. So, In this case we can had the header text by using header function. ob_end_flush clear the output buffer. ob_start function starts storing the output in the internal buffer and ob_end_flush is flushing this buffer then producing the content back to the page. If user sign out you don't wanna show them anything you can just use this with thank you message. If we change value of variable $redirect to true it will redirect users to http://google.co.uk.



No comments:

Post a Comment

Thanks For Comment Will get you Soon..

About Me

Welcome to Extra Tutorials! My name is Mohammed and I am the 22 year writer, website developer, and photographer behind the blog. Thanks for visiting! Tutorials Jackpot… In addition to Developer, I love to develop websites and I love to write. Starting a php Blog was inevitable for me. What began as a simple way to share all of my Tutorials with friends and family has developed into my Part time job.

Mohammed Padela

WHAT IS PHP PROGRAMMING

WHAT IS PHP PROGRAMMING
WHAT IS PHP PROGRAMMING

Follow Us

Popular Posts

Designed ByBlogger Templates