You need to investigate some php authentication systems. There are many available in varying degrees of ease of use. Try phpclasses.com, hotscripts.com, and so forth. If you want to learn more about the behind the scenes, I recommend the SitePoint books, Object Oriented Techniques with PHP (vol 2 covers an authentication system, but you kinda need to know the stuff in vol 1 to use it).