Ideally, what ought to happen is the government sets up a system with cryptographic key pairs in a government database.
Adults go to a drug store / grocery store / whoever participates and is licensed to do this. The store clerk checks your ID. If you're an adult, they will give you a public key. The public key comes in an envelope that has been sealed at a government facility. No one can see it until you open the envelope. You can obtain as many of these as you want (you have to pay the cost of the printing / stationary / program admin costs at the time of purchase).
To go on pornhub, you need to type in the public key. Porn hub encodes a message with the key and sends to the government database to get a yes / no.
Governments can prosecute any store that gives out keys to minors (like with alcohol).
Governments can prosecute porn sites that do not adhere to this protocol.
This is good because it provides a lot of points where bad actors may fall afoul of the law, and these bad actors were probably the same types going to commit otehr crimes anyway.
But the truth is, this will never happen, because sites like PornHub are not interested in keeping minors off. They want to get young kids (boys mostly, although I hear girls are getting more amenable) addicted to their porn.