Passing headers through PEAR::Request class [unsolved]
Posted: Sat Jan 21, 2006 3:10 am
I am making use of the HTTP-REQUEST package from PEAR to pass headers and form data.
I am able to retrieve information using GET but I want help to post data.
I have my sample application, where I should login to get access to other details. There is another page in the application which does not require login.
Login needs three parameters
Normally, this would set a cookie if the login is valid. With that we can go to other pages such as index.php and many others. This is the stage where I need help, I want to somehow login so that I can access other pages.
If username and password are not available, we can use home page for trial purposes.
Here is the code...This file needs Request.php from the package and request.php requires PEAR.php, Socket.php, URL.php for your reference...
Here is the output
I am able to retrieve information using GET but I want help to post data.
I have my sample application, where I should login to get access to other details. There is another page in the application which does not require login.
Login needs three parameters
Code: Select all
1. txtUserName - a username
2. txtPassword - a password
3. subAuthentication - submitIf username and password are not available, we can use home page for trial purposes.
Here is the code...This file needs Request.php from the package and request.php requires PEAR.php, Socket.php, URL.php for your reference...
Code: Select all
<?php
/**
* This will grab a webpage and display it
*/
include('../Request.php');
$req = &new HTTP_Request("http://raghavan20.100webcustomers.com/authentication.php");
$req->addPostData("txtUserName", "raghavan20", false);
$req->addPostData("txtPassword", "visitor", false);
$req->addPostData("subAuthentication", "submit", false);
$req->sendRequest(true);
print_r($req->getResponseHeader());
print_r($req->getResponseCookies());
//$req->addCookie();
$req->setURL("http://raghavan20.100webcustomers.com/viewBlog.php");
$req->addRawQueryString("action=viewBlog&blogId=1", false);
echo "<br />";
print_r($req->_url);
echo "<br />";
$req->sendRequest(true);
print_r($req->getResponseHeader());
echo $req->getResponseBody();
?>