A refurbished phone, in most cases ... meaning you can run the iPhone for up to eight years without issue. Samsung phones are a good option, though, but you’ll need to buy its newer, flagship models.
As Hebeisen says, the best way to keep yourself safe is simply to not use a phone that's no longer supported. If you're short on money, can't afford to upgrade just yet or you're using an older phone ...