You try to connect to some server on the internet. If that works, then the user is connected.
You can also query the OS whether the computer is connected to the network, but that kind of access does not guarantee that you can talk to the internet (or the server you care about).