My site is seoitc.com, we are using joomla for this site, but have 1 problem when i try auto redirect to anypage that show error: Warning: Cannot modify header information - headers already sent by ().
I tried change redirect to use js but cant use same status(302,303...) same as in php. Please help to fix this problem please.
Thanks!

Re: Can i change header redirect in php to javascript redirect with same status 80 80
Member Avatar

Your header() is declared after output to the page. Ensure that no html , whitespace or php-derived html or php errors are output before the header()

Re: Can i change header redirect in php to javascript redirect with same status 80 80

Thanks for replly, i write 1 function for redirect then i call it back at other functions so that showing this error.

Re: Can i change header redirect in php to javascript redirect with same status 80 80
Member Avatar

Ok. Unless you post your code, I can't see how we can be of further assistance. It would be guesswork on our part.

Re: Can i change header redirect in php to javascript redirect with same status 80 80
function wp_redirect($location, $status = 302) {
    global $is_IIS;

    $location = apply_filters('wp_redirect', $location, $status);
    $status = apply_filters('wp_redirect_status', $status, $location);

    if ( !$location ) // allows the wp_redirect filter to cancel a redirect
        return false;

    $location = wp_sanitize_redirect($location);

    if ( !$is_IIS && php_sapi_name() != 'cgi-fcgi' )
        status_header($status); // This causes problems on IIS and some FastCGI setups

    header("Location: $location", true, $status);
    ?>
    <script type="text/javascript">
        //window.location = "<?php echo $location;?>";
    </script>
    <?php

}

Im using wordpress, demo on http://www.codeit.vn/wp-admin/, please help .
Thanks!

Re: Can i change header redirect in php to javascript redirect with same status 80 80
Member Avatar

I can't see the point of the js - does it ever get implemented? The header() or return false will stop the function before the js is reached.

The code seems OK, but I don't know what happens with the external function calls:

 $status = apply_filters('wp_redirect_status', $status, $location);
 status_header($status);

If an error is returned, then that could cause php output, which will kill the header().

Also, if you have other code before this in your page, there may be output from that.

Re: Can i change header redirect in php to javascript redirect with same status 80 80

I tried config show all errors+ warning in phpini but just have that warning, i dont see any other error, on frontend thats working fine.

Re: Can i change header redirect in php to javascript redirect with same status 80 80

just curious, what happens when you put an

exit();

after the header() call?

If that doesn't solve the problem then put an

exit("End");

just before the header call and then view source after you run it to see if there is any white space or characters prior to the word "End" in the html source. If there is then you are, or something is, outputting content to the page prior to the header redirect attempt which means that headers have already been sent to the browser and a 302 is no longer possible at that point.

Re: Can i change header redirect in php to javascript redirect with same status 80 80
Member Avatar

Warning: Cannot modify header information - headers already sent by ()

Does it give a line number for the headers sent by... ? If so, print the block of code to which it belongs.

Re: Can i change header redirect in php to javascript redirect with same status 80 80

output started at /mnt/stor12-wc2-dfw1/554928/www.codeit.vn/web/content/wp-content/themes/Tersus/functions.php:1

I tried print exit('End') and its showing 1 <br /> at top.

Re: Can i change header redirect in php to javascript redirect with same status 80 80

strange i add ob_start(); at top of index.php its working

Re: Can i change header redirect in php to javascript redirect with same status 80 80

Thats not works :(, thats redirect to http://www.codeit.vn/wp-login.php and died :(

Re: Can i change header redirect in php to javascript redirect with same status 80 80
Member Avatar

output started at /mnt/stor12-wc2-dfw1/554928/www.codeit.vn/web/content/wp-content/themes/Tersus/functions.php:1

That's your answer. Do you have whitespace before the <?php tag? Or is there any html on that first line in the file?

Re: Can i change header redirect in php to javascript redirect with same status 80 80

I checked all files, i add all close tag ?>, dont have anyfile there is any html at first line in the file. Do i need to remove comment?

Re: Can i change header redirect in php to javascript redirect with same status 80 80
Member Avatar

I you showed the code, it would keep us from guessing...

Re: Can i change header redirect in php to javascript redirect with same status 80 80

I fixed, i remove all speace and change encode to utf8, thats working fine.
Thanks for your help, if you have any client want do seo please introduce us we will do free 1month for you.
Thanks again!

Re: Can i change header redirect in php to javascript redirect with same status 80 80
Member Avatar

Thanks. BTW - I don't know if it's my connection, but your site is taking a very long time to load.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.