so this is driving me crazy I understand the error. But I am trying to redirect to the page regardless. meaning : if condition = 1 => redirect to this page... or redirect to another. any other alternatives?
Asked
Active
Viewed 168 times
1
-
http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php – morissette Apr 09 '14 at 15:25
2 Answers
2
Have you tried using <?php ob_start(); ?>
at the start of the page?

Zy0n
- 810
- 2
- 14
- 33
-
no haven't heard about it. I made it work with javascript actually but I am still interested in finding out how to do it in php – cppit Apr 09 '14 at 15:24
-
Try doing this at the start of your page were you're sending your headers without your javascript solution. Should work. – Zy0n Apr 09 '14 at 15:26
-
You got there with your answer while I was writing it. Oh well! :D – Eva Lauren Kelly Apr 09 '14 at 15:30
-
1
You need to make sure nothing is being sent to the browser before you send the redirect header. One possible solution (although quick and dirty) is using output buffering, so at the start of the page put
<?php
ob_start();
// any code you need to check whether to redirect
// note that output from between the ob_start()
// and the ob_end_clean() won't be sent to the user
ob_end_clean();
and then do your redirection checks and redirection. Remember, don't let anything output. So no echos, etc.

Eva Lauren Kelly
- 403
- 1
- 4
- 15