tags:

views:

50

answers:

3

Hi I am trying to write a script to login a web application using PHP CLI script

like

   <?php
     $post_data = array(
 'user_name' => 'abc',
 'user_password'=>'XYZ@@11',
);

$url ='http://www.myapplication.com?action=Login&amp;module=Users';     
$hat = new  HttpRequest($url,HTTP_METH_POST);
$hat->setPostFields($post_data);
    $hat->send();
    $res = $hat->getResponseData();
    print'<pre>'; print_r($res); print '</pre>';
   ?>

i want post the username and password to this page and trying login the application i dont know is this the right way doing this .... please suggest me , how to go about this....

+2  A: 

You could use the cURL library to create a POST request.

Ólafur Waage
A: 

If the page you are accessing uses HTTP Basic authentication, take a look at HttpRequest::setOptions and set the httpauth and httpauthtype options on your request. You'll need something like this:

$options=array();
$options['httpauth']="abc:XYZ@@11";
$options['httpauthtype']=HTTP_AUTH_BASIC;

$hat->setOptions($options);
Paul Dixon
A: 

Looks fine - I don't know much about HttpRequest but you may need to do some work to maintain cookie data, so you stay logged in

David Caunt