• Register
0 votes
279 views

Problem :

I am new to CodeIgniter. The Codeigniter is raising issues about my registration model that it is sending header information before anything else. I thought that the models are there only for holding the database queries methods and nothing more. Can anybody please explain me about solution on my below error?

I am facing below error I am trying to run my php CodeIgniter project.

Cannot modify header information - headers already sent by codeigniter

8 4 2
2,300 points

1 Answer

0 votes

Solution :

People who are new to codeigniter often face this issue. Few of the Host Providers have tendency to use the PHP header(); to redirect the Site, So for those kind of specific   servers if we are using the PHP header() then it will show us above error. In the Code Igniter the redirect(); function is using the PHP header() to redirect the URL. So this is the reason behind our error.

The only solution on the error is to use the JavaScript to Solve this Issue, I have used it and it works for me as shown below.

//Normal Code to redirect
redirect('site/function1');

//Alternate Code to fix this issue
$myurl = 'site/function1';
echo'
<script>
window.location.href = "'.base_url().'index.php?/'.$myurl.'";
</script>

Hope this solution helps you too.

5 2 1
4,980 points

Related questions

0 votes
1 answer 64 views
64 views
Problem : When I try to lock the LOGIN button, it shows me the below error, I am unable to fix this error.I am very new in php. &ldquo;Warning cannot modify header information - headers already sent by (output started at /home/content&rdquo;
asked Jan 30 jwilliam 3.9k points
0 votes
1 answer 15 views
15 views
I am beginner on CodeIgniter, and while i go on run into problems that, defining global variable in codeigniter controller.
asked Sep 26 Daniel Anderson 4k points
0 votes
1 answer 10 views
10 views
In this case specifically i want to know how load the views via controller
asked Sep 16 Daniel Anderson 4k points