I am also having problems with this and am asking myself the same questions as you. A lot of good suggestions have been given but yeah, obviously it takes some dicipline.
You just have to find yourself a method that works for you and that you can be diciplined about.
What works best for me and something I always strive after, is setting a progressive "cashout limit" that I may increase throughout the session but never lower.
Example: I deposit €20 , I get up to €142. At this point, €100 is my bottom line, I won´t go under this. However if I keep on winning before I reach that point, and end up having maybe €190, I´d increase that withdrawal point to €150 as it would still leave me with €40 to wrecklessly play however I wan´t. It´s double the amount I deposited and I already had lots of fun, If I can not be happy about that with a €150 withdrawal on top of it, something is seriously wrong. (As it is most times

)
Being focused, well rested, healthy or fit, it all helps tons as it increases your focus and makes it easier to be diciplined.
Another tip that won´t work for me but I know it works for others, is simply to set a time limit you stick too. Either by your self or using the casinos "session limit" if available. I am sure you have a rough idea about how long time it takes before you start getting a bit unfocused and tilting tendencies start occuring, set a time limit that prevents you from getting to this point. When you see your €190 balance after a €20 deposit, unable to keep playing until next day, it will then be easy to settle for a withdrawal and maybe leave something in the account for the next day so you don´t need to redeposit.
I hope you find something that works for you!