Refrigeration is fundamental!
If you want make your gallon of milk last as long as possible, you have to take refrigeration seriously. I know that sounds really dorky, but food safety is important! Learning how to store milk correctly will keep you from accidentally getting sick. Plus, storing your milk properly will also help you keep milk fresh as long as possible. That means you won't have to deal with the nasty smell of spoiled milk or accidentally take a sip of something rotten. How long you can keep milk is almost totally dependent on how and where you store milk in the fridge, and it turns out that there is a right way to store milk in the fridge and a wrong way.
According to the US Department of Agriculture, milk and other dairy products should be kept in the refrigerator at or, ideally, below 40°F. If the temperature gets higher than that, bacteria can start to grow in the milk, which is what causes the rotting and the smell. (Though, for what it's worth, you can generally leave milk out of the fridge for up to two hours without any serious issues.) For best results, you want to store and serve your milk between 35° and 40°F. That's according to the Western Dairy Association, a non-profit, dairy farmer-funded organization that promotes, unsurprisingly, dairy.
The best way to extend the shelf life of milk, then, is to make sure that the milk primarily stays in an environment that's less than 40°F. That means keeping milk in the coldest part of the fridge. That's definitively not the slot in the door where it looks like cartons are supposed to go; even the USDA recommends against storing perishable foods in the fridge door, writing, "temperature of the storage bins in the door fluctuate more than the temperature in the cabinet."
The coldest part of your fridge, as Nicole Sforza writes for Real Simple, is the bottom shelf, all the way in the back. That's where you should be keeping your milk if you want it to last as long as possible.
If you do it correctly, refrigerate your milk as soon as you get home from the grocery store and keep that milk cold, you'll be drinking it for up to two weeks, which is basically a whole lifetime if you ask me.