Passing headers through PEAR::Request class [unsolved]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Passing headers through PEAR::Request class [unsolved]

Post 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
Last edited by raghavan20 on Wed Jan 25, 2006 9:06 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it would appear that the page isn't sending any cookies...
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post 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.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post 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.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post 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?
Post Reply