1

got a really bugging issue for a while now and cant figure it out. basically the code below is part of a function and i checked and there is no output printed to the browser:

    case 'Failed': // if it fails...
        switch ( $unencrypted_values['Status'] ) {
            case 'NOTAUTHED':
            case 'REJECTED':
            case 'MALFORMED':
            case 'INVALID':
            case 'ABORT':
            case 'ERROR':
                $purchase_log = new WPSC_Purchase_Log( $unencrypted_values['VendorTxCode'], 'sessionid' );
                $purchase_log->set( array(
                    'processed'  => WPSC_Purchase_Log::INCOMPLETE_SALE,
                    'notes'      => 'SagePay Status: ' . $unencrypted_values['Status'],
                ) );
                $purchase_log->save();
                // if it fails redirect to the shopping cart page with the error
                // redirect to checkout page with an error
                $error_messages = wpsc_get_customer_meta( 'checkout_misc_error_messages' );
                if ( ! is_array( $error_messages ) )
                    $error_messages = array();
                $error_messages[] = '<strong style="color:red">' . $unencrypted_values['StatusDetail'] . ' </strong>';
                wpsc_update_customer_meta( 'checkout_misc_error_messages', $error_messages );
                $checkout_page_url = get_option( 'shopping_cart_url' );
                if ( $checkout_page_url ) {
                    header('Location: '.$checkout_page_url );
                  exit();
                }
                break;
        }
        break;

thats part of the function but when i run my script i get the error message:

Warning: Cannot modify header information - headers already sent by (output started at       /home/******/public_html/wp-content/themes/reallywildflowers/header.php:13) in      /home/reallyw/public_html/wp-content/plugins/myplugin/merchants/sagepay.php on line 598 - See more at: http://website.com/products-page/transaction-results/?crypt=NzsPDC0yayoLATltUScRGBA6HTw9NTcCJXMqezgmMVkJKh0LOSYzSy4rBVwFFREcAG8MAXgSPwY8IgpNGAZDLwEhChcqFS4oJioOBEZFUkhXd15Ab3ZiX31oPWkkIB0wAHIVT2B3YCl8d1sUQURXSUl7LzpgbBdTDwpGCkA1XUAlCVtObnBlFm8PBlYCGhFEUHxATX4AADgKGFkENjgpWSkOOjsQZxcPLTwOSgQmAAoRIxpFFQACKAELLx8nGxYNJyAKHQokJR4lOlZ0NiAmMSELSDsOcwQOOjsHTUo5JC0nBys8fgY/DT0PAl1KRENKIBwLGy0zMzg9Lx9MBEkqMkIMLy4OfBslHhg8ekM8LTUtfyc6GXBmPR15L3pRNwQLABsXCD18ACIaD011FgcRTSAmCREsMmtcfX5Z

line 598 is this one from the code:

header('Location: '.$checkout_page_url );
misulicus
  • 437
  • 2
  • 6
  • 16
  • 1
    *i checked and there is no output printed to the browser* - check again - maybe there's a whitespace before your first php tag? – 1615903 Oct 04 '13 at 09:26
  • i checked and rechecked it..there is nothing printed to the browser..no spaces either. – misulicus Oct 04 '13 at 09:28
  • It says output was sent by header.php on line 13. Did you check it? Maybe there is a closing Tag "?>" and some newline or stuff there. If so, remove the tag, it is not needed. – Stephan B Oct 04 '13 at 09:32
  • @misulicus are you check our answers – Padmanathan J Oct 04 '13 at 10:07

3 Answers3

0

This error usually appears if you have some thing printed before redirecting .

The easiest fix to solve your problem is

If you have access to change your php.ini configuration file you can find and change or add the following

output_buffering = On

or call

ob_start()

before redirecting

There are several SO postings describing this problem and I often ask this question when I am evaluating a php developer while hiring :)

Headers already Sent

hope this helps

Community
  • 1
  • 1
Aravind.HU
  • 9,194
  • 5
  • 38
  • 50
0

Check the file have any space in the beginning of your script.

Else try below could help,

ob_start();
header('Location: '.$checkout_page_url );
ob_flush();
Nes
  • 304
  • 1
  • 10
0

Call ob_start(); or put @ into session_start like @session_start

Alternative solution is

<script type="text/javascript">
window.location.href = '<?php echo $checkout_page_url; ?>';
</script>
Padmanathan J
  • 4,614
  • 5
  • 37
  • 75