Post Made Community Wiki by Alan Barber
source | link

In your case, get up and walk around a little. If it's hard to get back in "the zone" it's probably because you're too far in. Doing stuff on the web is just another zone and one that's easy to lose track of time in. Give your brain the break it clearly wants and go for a walk, take a wiz, ideally in a restroom, or talk to a random co-worker. We do a lot of stuff behind the scenes on auto-pilot. Breaks are not bad for coding, they are good, but the idea is to stop firing on all cylinders for a while and see what your back burners come up with while the more conscious part of your mind gives it a rest. Good devs aren't human calculators. Let the parts of your brain that do all the intuitive and pattern-matching stuff on autopilot do their thing for a while.

If this isn't just a coding problem, you might want to consider ADD.