Have you tried any of this yourself? If not, have a look at some of the usernotes in the PHP manual under the CURL section. Plenty of people commented upon this.
We're not here to write your scripts for you, so please don't ask us to (as it seems you already have); however, we're more than happy to help you fix problems you run into along the way.