Tuesday, 10 December 2013

Output Buffering Start Function in php

Output Buffering Start Function In 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 outputbuffering 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 :-
output buffering start function
output buffering start function (Screenshot1)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?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
output buffering start function (Screenshot2)
ob_start function will be declare top of the page. ob_start functioncan be called without arguments. Ob_start function will store pageoutput 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 variabe $redirect to true it will redirect users to http://google.co.uk.

Read More Extra Tutorials

No comments:

Post a Comment