[thelist] PHP to access password protected page

Simon Willison cs1spw at bath.ac.uk
Thu Oct 16 13:40:34 CDT 2003


muinar wrote:

> Is this possible via PHP scripting?
> 
> 1. Send username / password to a web page (which is htaccess protected)
> 2. Insert some values into a form
> 3. Read the results after submitting.

My PHP class HttpClient is designed specifically to do this:

http://scripts.incutio.com/httpclient/

The code you would use would look something like this:

<?php
include('HttpClient.class.php');

$client = new HttpClient('your-domain.com');
$client->setAuthorization($username, $password);
$client->post('/path/to/script.php', array(
     'formvar1' => 'Some value',
     'formvar2' => 'Some other value'
));
$pageContents = $client->getContent();

?>

At this point, $pageContents would contain the HTML returned by the 
server after the form was submitted.

Hope that helps,

Simon Willison
http://simon.incutio.com/




More information about the thelist mailing list