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

Do not put it as a duplicate without reading the full question.

I know this has been discussed many times.

But this is a different case.

I am making a simple ajax call for a php method that looks like this:

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'm just trying to get the data that is transferred using an ajax call.

But I do not get the data sent by ajax call, instead I 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 do not use session_start (); somewhere in my project.

This error points to the session_start () method, which is located in the Session.php file of the Codeigniter libraries. It does not indicate anywhere in my code, so I am not sure where to look for problems.

I have already checked the answers all over the Internet, and none of them seem to have solved this problem.

Can someone explain to me why I am getting this error and how can I prevent this?

Thanks.

Edit: As suggested in the other answers, I checked and removed the spaces 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(){ } }); }); 
+7
ajax php codeigniter session
source share
3 answers

Use F12 in your browser during ajax call and click on the console and network to see your ajax call data, sometimes an error occurs due to outdated methods, and you need to change some php settings in php.ini as

 always_populate_raw_post_data = -1 

also if you use routes.php make sure to use the correct path

+1
source share

Could you check this answer How to fix the "Headers Already Submitted" error in PHP

There is probably some output / or error that occurred before the header is set.

+2
source share

When you make an AJAX call, you call the Code-igniter entry point, which loads all the necessary libraries, including starting a session.

I don’t know what the log_message() function log_message() , but I believe it is trying to print to STDOUT, and then one of your code or Code Igniter is trying to send some headers.

Can you post more information about your log_message () function ???

0
source share

All Articles