Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot send session cache limiter - headers already sent - CodeIgniter (Session.php)

I know this is discussed already many times, but I think this is different case.

I am making a simple ajax call to a php method which is as below:

public function updateAbout()
{
    log_message('debug', "updateAbout is called", false);   

     log_message('debug',$this->input->post('fname'), false);

   log_message('debug', "updateAbout success", false);   

}

In this method I am simply trying to get data which is passed by ajax call.

But I don't get data posted by ajax call instead get 2 errors:

Severity: Warning --> session_start(): Cannot send session cache limiter - headers already sent ...\..\\libraries\Session\Session.php 143
Severity: Warning --> Cannot modify header information - headers already sent ..\..\libraries\Session\Session.php 171

Note:

I am not using session_start() anywhere in my project.

This error is pointing to session_start() method which is in Session.php file of CodeIgniter libraries. It is not pointing to anywhere in my code so I am not sure where do I look for issues.

I have already checked answers all over internet and none of them seem to solve this issue.

Why am I getting this error and how can I prevent this?

Edit:

As per suggestions in other answers, I have checked and removed spaces in <?php ?> in all my codes.

Here is my JavaScript code where ajx call is made.

      $("#btnupdateAbout").click(function(){

      $fname=$("#updatefname").val();
      $lname=$("#updatelname").val();
      $country=$("#updatecountry").val();
      $locality=$("#updatelocality").val();

      if($('#optradioMale').is(':checked')) { $gender="Male"; }
      else{$gender="Female";}

       $.ajax({

           url:"http://localhost/Voyager/ProfileControls/updateAbout",
           data:{'fname':$fname,'lname':$lname,'country':$country,'locality':$locality,'gender':$gender},
           method:"POST",
           contentType:false,
           cache:false,
           processData:false,

           success:function(){

           }

       });
   });
like image 976
Dheeraj Kumar Avatar asked May 19 '17 11:05

Dheeraj Kumar


2 Answers

Could you please check this answer How to fix "Headers already sent" error in PHP

Probably, there is some output/or error thrown before the header is set.

like image 96
prab Avatar answered Oct 03 '22 09:10

prab


Make use of F12 in your browser during the ajax call and and click on console and network to see your ajax call details, sometimes an error occur due to deprecated methods and you need to change some php settings in php.ini like

always_populate_raw_post_data = -1

also if you are using routes.php make sure you are using the correct path

like image 34
Nassim Avatar answered Oct 03 '22 08:10

Nassim