I learned PHP by reading the documentation (
www.php.net), but I'm not sure if that's the best way for you to find what you're looking for. I can't say I've ever had to do something like that, but perhaps you could run a few search strings in Google, and find something? Anything I can think of at the moment is needlessly complicated for what you're looking for.
Or, you could ask our benevolant forum overload (Brandon for short), because the forums have that little "LED" that turns green if a user has logged on. Perhaps you can get some code from that (or he can help write some code from that)?