Welcome Guest, Not a member yet? Register   Sign In
Getting php error on production but not development
#1

[eluser]Cgull[/eluser]
Hello,

I have this web site where I get this error on live:


A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /home/highland/public_html/application/controllers/order/checkout.php:203)

Filename: libraries/Session.php

Line Number: 672


But not on my local server.

Any idea why would this happen?
#2

[eluser]GI-Joe[/eluser]
[quote author="Cgull" date="1339224452"]Hello,

I have this web site where I get this error on live:


A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /home/highland/public_html/application/controllers/order/checkout.php:203)

Filename: libraries/Session.php

Line Number: 672


But not on my local server.

Any idea why would this happen?[/quote]

Please show you code
#3

[eluser]Cgull[/eluser]
I am posting the code of the function that it looks like it is moaning about:
Code:
function calcDelivery()
{
  $this->load->helper('form');
  $this->load->model('order/checkout_model');
  $totalWeight = 0;
  
  foreach($this->cart->contents() as $items):
   $qty = $items['qty'];
   foreach ($this->cart->product_options($items['rowid']) as $option_name => $option_value):
    if($option_name == 'weight'):
     if($option_value == '250g')
      $option_value = 0.25;
     else
      $option_value = 1;
    endif;
     $totalWeight += floatval($option_value) * $qty;
   endforeach;
  endforeach;
  if($totalWeight < 1)
   $totalWeight = 1;
  else
   $totalWeight = ceil($totalWeight);
  $delivery = $this->checkout_model->calcDelivery($totalWeight);
  $deliveryTotal = floatval($delivery);//round(floatval($totalWeight), PHP_ROUND_HALF_UP);
  
  $subtotal = $this->cart->format_number($this->cart->total());
  $total = $subtotal + $deliveryTotal;
  echo "R ";
  printf("%.2f", "$deliveryTotal");
  echo '&lt;input type="hidden" name="total" value="' . $total  . '" id="totalval" /&gt;';
  $this->session->set_userdata('deliveryVal', $deliveryTotal);
  $this->session->set_userdata('total', $total);
}

Line 203 is this one:
Code:
echo "R ";

Thank you
#4

[eluser]GI-Joe[/eluser]
Please check whether you are printing anything before redirecting to a view or some url in checkout.php
#5

[eluser]GI-Joe[/eluser]
Just try by removing

Code:
//echo "R ";

You should not print anything before using
Code:
redirect('path/to/method/or/view');

#6

[eluser]Cgull[/eluser]
Thank you,

I will look into moving the printf and echo to the view itself, but still, why don't I get this error on the local machine?
#7

[eluser]Cgull[/eluser]
Sorry, another thing, this function is being called in a view with an ajax call:
Code:
$(document).ready(function()
{
var delivery = $('#delivery').val();
var weight = $('#sendform').serialize();

$.ajax({
    type: "POST",
    url: "&lt;?php echo base_url(); ?&gt;order/checkout/calcDelivery",
    data: {delivery: delivery, weight: weight},
    success: function(data){
    $('#deliveryCalc').html(data);
    $('#deliveryVal').val(data);
    var total = 'R ' + (parseFloat($('#totalval').val())).toFixed(2);
    $('#total').html(total);
   }
  });
And there is no redirect in the checkout controller file at all.
#8

[eluser]CroNiX[/eluser]
CI's output is buffered when using views, etc. When you echo directly from a controller, that output gets sent immediately followed by the contents of the buffer.

It's best to send any output to the buffer instead of echoing it directly.

Code:
$output = "R ";
$output .= printf("%.2f", "$deliveryTotal");
$output .= '&lt;input type="hidden" name="total" value="' . $total  . '" id="totalval" /&gt;';

$this->output->set_output($output);

Your session is sending output to the browser (probably a cookie, sent with a header), so that's where the buffering is coming into play.




Theme © iAndrew 2016 - Forum software by © MyBB