I have an external site which requires me to
a. login
b. post form (with 2-3 dyanamic parameters)
I need a PHP script to automate this behavior. i.e. the script should first login with a username/password and then navigate to the URL and submit the form (using dyanamic parameters)
How can I do the same using PHP?
I recommend using this class:
http://semlabs.co.uk/journal/object-oriented-curl-class-with-multi-threading
It will be something like this:
$c = new CURLRequest();
$c->retry = 2;
$c->get( $url, $this->curlOpts );
$url = 'https://secure.login.co.uk/';
$opts = array(
CURLOPT_USERAGENT => 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)',
CURLOPT_COOKIEFILE => 'anc.tmp',
CURLOPT_COOKIEJAR => 'anc.tmp',
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_TIMEOUT => 120
);
$opts[CURLOPT_POSTFIELDS] = 'username=user&password=pass&submit=1';
$request = $c->get( $url, $opts );
N.B. Some sites require you to download the login page first to set a cookie.
Also, you need to url_encode special chars in the post fields.