Set a timer, make yourself get off when it goes off. Do all the stuff you have to do, like checking email, at the beginning, so when the timer goes off you can't be like "Oh, I still have to do this" and wind up staying online another 4 hours.
I always spend too much time online but sometimes the trick to just get yourself out of house. Go for a walk, do some shopping, do anything but sit around where you usually use the computer.
Spending too much time online means that you don't have enough things to do in your life. Think about getting a job or getting something else in your life that will genuinely keep you busy so that you spend your time on more important things.