Debugging is about finding the problem. So you can add die() statements into IF statements where you believe the problem might be and see if it is getting to that place in the code.
Then write the values you expect to be set and see if they are set correctly. Maybe a die() statement on the redirect page to see if it is actually redirecting and then returning or never going to the page in the first place.
You have to look and come up with a theory about where the problem is happening and then test to narrow it down. It isn't something I can be specifically helpful with since I'm not that familiar with your application. Why is the session clear code there in the first place?