On South West Trains you can only buy a ticket on the train if the ticket office is closed and there's no ticket machine BUT you must buy what's known as a "permit to travel" which proves where you got on the train. If you have nothing you will be fined on top of having to buy a full priced ticket.