CodeIgniter – Redirects Have Stopped Working In Production!

CodeIgniter

Usually, things don’t just stop working. That’s particularly true of computer programs. Normally something has changed, you just haven’t realised quite what it is yet.

CodeIgniter is a still relatively popular PHP framework. Many consider Laravel to have superseded it, but there are pros and cons to both and both enjoy a good following still.

You’ve spent a while coding your next website, you’ve deployed it into live and BOOM! You submit a form, and it’s not redirecting as it used to. It may just be showing a white page or displaying some other result. Either way, you’re not too sure what’s happening.

Why, Oh Why?!

The cause? Well, that’s likely to be differences in environments. Your localhost environment will be different from your production environment. Some are likely intentional, some unintentional and some relatively subtle.

Maybe you’re Windows locally but running a Linux server. That can cause untold frustration due to relative differences in the platforms. For example, Windows is very forgiving of unintentional (or misplaced) capital letters whereas Linux hauls you over the coals for it.

Your security configuration is likely to be much more robust in Production than it is Development. Maybe you don’t even control the security configuration of your Production system because you’re on shared hosting and your hosting provider is locking it down?

Despite all these differences, there’s however usually one common explanation for redirects working on localhost and then not in production when it comes to CodeIgniter (or PHP in general).

What’s Wrong?

You’re triggering output. OK, well we don’t know this for sure – however, it is the most common problem and one that you should check (and recheck!) again if you’re struggling with redirects stopping working once you’ve deployed your application.

Now, I know you’re going to swear blind that you’ve already checked it. I believe you! But, for the sake of your sanity, it’s worth checking at least one more time right?

A common one is debugging messages output in places such as Models. Whilst your Windows setup might tolerate this, your Linux setup is likely to baulk. If you’re seeing some unformatted text output on your screen rather than redirecting after you’ve submitted your form, it’s likely because of this very scenario.

Ensure, prior to your redirect, these common commands are *not* being used as they will cause the page to not redirect as intended in Linux environments.

  1. echo
  2. print_r
  3. print
  4. dump
  5. var_dump

If you’re running any of these after you’ve submitted your post request but before your redirect has been performed you will cause yourself issues!

Regardless of the environment, and regardless of whether your environment tolerates it, it’s really bad practice and not advisable to output prior to redirecting under these circumstances so avoid at all costs!

Had this problem yourself? Have a different solution? Maybe yours still isn’t working? Let us know in the comments below!

You may also like...

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x