# Useful Information about Function Header (PHP)

**URL:** <https://forum.kirupa.com/t/useful-information-about-function-header-php/27755>\
**Category:** programming\
**Created:** [August 6, 2003, 9:02am UTC](https://forum.kirupa.com/t/useful-information-about-function-header-php/27755 "2003-08-06T09:02:54Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Drunken](https://avatars.discourse-cdn.com/v4/letter/d/a4c791/32.png) [@Drunken](https://forum.kirupa.com/u/Drunken)\
**Post date:** [August 6, 2003, 9:02am UTC](https://forum.kirupa.com/t/useful-information-about-function-header-php/27755/1 "2003-08-06T09:02:54Z")

</div>

heya!

For a long time I have many problems with function Header in PHP. This cause an error of outup buffering when we have something like this:

```php

<?php 
echo "Hi world!";
header ("location: main.php");
?>

```

this cause a error that i refer previous. The first solution for this was using javascript like this:

```php

echo "<SCRIPT>window.location=\"main.php\"; </SCRIPT>";

```

but this isn’t very good because when user click back on browser isn’t possible, this function not permit Back.

Then I have to found another solution Ⓜ , finally :geek:  
like this:

```php

<?php 
ob_start();

  echo "Hi world!";
  header ("location: main.php");

ob_end_flush();
?>

```

Using this functions (ob\_start(); and ob\_end\_flush(); ), we can have many outputing to buffer without cause error 🙂

You can found more information about this functions in  
[www.php.net](http://www.php.net)

I test this in PHP 4.0.6 and 4.3.1

I hope this help someone :azn:  
xauz!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 6, 2003, 1:58pm UTC](https://forum.kirupa.com/t/useful-information-about-function-header-php/27755/2 "2003-08-06T13:58:05Z")

</div>

well if you are going to do that, then why not just take the output code (echo) out. The ob\_start disallows output being displayed… so that entire code could be shortened to

```php

<?
header("Location: whereever.php");
?>

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 6, 2003, 2:25pm UTC](https://forum.kirupa.com/t/useful-information-about-function-header-php/27755/3 "2003-08-06T14:25:36Z")

</div>

[here is a good article about this](http://www.devshed.com/Server_Side/PHP/OutputBuffering/page1.html)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 6, 2003, 3:22pm UTC](https://forum.kirupa.com/t/useful-information-about-function-header-php/27755/4 "2003-08-06T15:22:54Z")

</div>

Jubba can be but if you need to have something like this

```php

<?php

if ($status == "loginok") {

 echo "Validation Ok!"

}else {

header ("location: main.php");
}

?>

```

you can’t have only header (“location: main.php”);

(-:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 6, 2003, 3:30pm UTC](https://forum.kirupa.com/t/useful-information-about-function-header-php/27755/5 "2003-08-06T15:30:42Z")

</div>

look at your code again. That would work without using the ob\_start/ob\_flush because of the if statement. If its not true then there is no output and the header gets parsed… if the statement is true… the output is run and the header doesn’t get parsed…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 6, 2003, 3:44pm UTC](https://forum.kirupa.com/t/useful-information-about-function-header-php/27755/6 "2003-08-06T15:44:19Z")

</div>

No… don’t works … the logical is that work but not …

As i was sad, i test in versions 4.0.6 and 4.3.1 …

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 6, 2003, 3:49pm UTC](https://forum.kirupa.com/t/useful-information-about-function-header-php/27755/7 "2003-08-06T15:49:58Z")

</div>

works fine on: 4.3.2

must be the older versions… but I never had trouble with this before I upgraded my server…

eh whatever…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 6, 2003, 4:14pm UTC](https://forum.kirupa.com/t/useful-information-about-function-header-php/27755/8 "2003-08-06T16:14:54Z")

</div>

Doesn’t PHP have HTTP Headers like ASP?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 6, 2003, 4:19pm UTC](https://forum.kirupa.com/t/useful-information-about-function-header-php/27755/9 "2003-08-06T16:19:51Z")

</div>

[http://us4.php.net/manual/en/function.header.php](http://us4.php.net/manual/en/function.header.php)
