I found a trick that worked for my Lumia 1520, and seeing how frustrating it was, I decided to set aside some time to come here and attempt to help other people. On my phone, when it stops recognizing the charging cable or is stuck in airplane mode, I massage the bottom middle portion of my phone. Right where the middle windows button is at the bottom of my phone, I firmly (pretty hard) press down and rub over that area several times.
If the phone isn't charging, I unplug the charger, then firmly press down and rub on the windows button with my thumb for a like 2 or 3 seconds, then plug it in and voila, it's charging.
If the phone is stuck in airplane mode, I firmly press down and rub on the windows button with my thumb for like 2 or 3 seconds, then restart the phone and voila, it's no longer stuck in airplane mode.
Seems like this is related to the connectors of something in that area of the phone. I keep my phone in my front pants pocket, and sometimes when I move to get out of my vehicle, my leg would slide against the steering wheel. Sometimes my phone would be in the way and get caught in between for a brief moment, so this may be what caused it in my case. I hope this works for you people.