From http://www.jonasjohn.de/snippets/php/curl-example.htm