简体   繁体   中英

redirect to a page without Warning: Cannot modify header information - headers already sent by

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?

Have you tried using <?php ob_start(); ?> <?php ob_start(); ?> at the start of the page?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM