You could probably use CURL for the logging in on the url to automate it based on the link Karl supplied.
Not tested... but shouldnt be any problem.
For the code to build it up; Just use Google
Good advice though to put it somewhere out of 'public html". as Karl sorta pointed out.