Thats not an easy question, but I think an easy way to implement a feature might be to have 2 tables (all users (lets call it 'users'), and one containing the users last activity time (lets call it 'user_ping')) Everytime the user makes a request it gets logged in user_ping...then to differentiate online vs offline users simply query the users with a ping time in the last 5 minutes.
OF course this is not the entire solution or completely fool proof, you would have to get more tricky maybe with ajax calls and keystrokes to be more accurate...but it is an easy start using only PHP.