Page 1 of 1

Passing headers through PEAR::Request class [unsolved]

Posted: Sat Jan 21, 2006 3:10 am
by raghavan20
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

Code: Select all

1. txtUserName - a username
2. txtPassword - a password
3. subAuthentication - submit
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...

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();

?>
Here is the output

Posted: Sat Jan 21, 2006 3:21 am
by feyd
it would appear that the page isn't sending any cookies...

Posted: Wed Jan 25, 2006 7:30 pm
by raghavan20
I have come up with a new example...
A simple form

Code: Select all

<body>
<?php 
if (isset($_POST["subState"])){
	echo $_POST["state"];
}

?>
<form method="post" action="">
	<input type="text" name="state" value="" />
	<input type="submit" name="subState" value="submit" />
</form>
</body>
A simple [url=http://assorted.100webcustomers.com/docs/example.php]HTTP request[url]

Code: Select all

<?php
$req = &new HTTP_Request("http://assorted.100webcustomers.com/docs/sampleForm.php");
$req->addPostData("state", "chicago", false);
$req->addPostData("subState", "submit", false);
$req->sendRequest(true);
print_r($req->getResponseHeader());
echo $req->getResponseBody();
?>
This code on execution returns the form instead of echoing 'chicago'. I am totally new to this concept, so please explain me as if I am a novice.

Posted: Wed Jan 25, 2006 8:08 pm
by raghavan20
I have got it now. Earlier, I did not mention the method to use, POST or GET. But the thing is, it returns the value along with the form.

Posted: Wed Jan 25, 2006 9:05 pm
by raghavan20

Code: Select all

$req = &new HTTP_Request("https://accounts.craigslist.org/login?rt=P&rp=/che/H");
$req->sendRequest(true);
print_r($req->getResponseHeader());
echo $req->getResponseBody();
I am able to access all pages but not the pages with SSL, https. There is no response header itself, is there is something that can be done?