First of all, remember that the number one rule in avoiding foreclosure is "Don't wait until the last minute." By the time you get to the last minute before foreclosure, you will owe thousands of additional dollars in late fees and court costs, and your credit rating will have taken a substantial hit. In addition, there is no guarantee that you will be able to stop the foreclosure; a thousand small things could get in the way of your plans.
In most states, however, if you reinstate the loan at any point prior to the foreclosure sale, the lender has to stop the foreclosure. Also, remember that reinstatement includes all missed payments, as well as court costs and late fees, and the bank has to verify payment before they will stop the sale.
Most people don't have that kind of money, however, so they may consider declaring bankruptcy. Bankruptcy temporarily removes your obligation to repay most debts, so it will stop the foreclosure temporarily. However, bankruptcy is no quick fix. You have to make a bankruptcy plan that requires you to give up assets (possibly including your home), cut your expenditures, and restructure your debts. In addition, bankruptcy hurts your credit rating. You can avoid foreclosure and catch up on your loan using bankruptcy, but don't think of it as a safety net.
Finally, beware of so-called offers that require you to sign over your house deed to a third-party. These scams take ownership of the property, but your name is still on the loan, so the bank still comes after you.