I'm sure some of the PHP frameworks have this already in them. But if you want to build your own, here is a very rough process for it. If you need more specific .