1

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?

1
  • 2
    CURL is the magic word here. coderscult.com/how-to-post-data-with-curl-in-php Just try around a little bit. As soon as you have some code to show us I can try to lead you into the right direction. Commented May 16, 2013 at 13:01

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.