Re: Question regarding HTTP_Request

From: Date: Fri, 23 Jul 2004 06:06:49 +0000
Subject: Re: Question regarding HTTP_Request
References: 1 2 3 4 5 6  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-13821@lists.php.net to get a copy of this message
On Fri, 23 Jul 2004 01:00:28 -0400, Alex Shi <chpshi@stonix.com> wrote: > > > > > > I can use HTTP_Request to simulate a login. I know that if > > > > > > login is correct, the remote site will return a cookie, and the > > > > > > url will be changed/redirected to a new location. So if I know > > > > > > the correct uid/pwd and the new location's url, there will be > > > > > > no problem, because I can just send a request to the new > > > > > > location. > > > > > > > > > > > > However, the problem is, if login is incorrect, the site will also > > > > > > return a cookie, and the url will be redirect another location. > > > > > > So, if I don't know if the uid/pwd is correct, how can check > > > > > > login result? > > > > > > > > > > > > All I know about this package's methods are as following: > > > > > > > > > > > > setURL (), > > > > > > setMethod (), > > > > > > addPostData (), > > > > > > addGetData (), > > > > > > sendRequest (), > > > > > > getResponseBody (), > > > > > > getResponseCookies (), and > > > > > > addCookie (). > > > > > > > > > > > > I cannot figure out with these methods how to get redirected > > > > > > response. Any one can suggest a solution? > > > > > > Thanks in advance! > > > > > > > > > > > > > > > > Since you're planning on making multiple requests and dealing with a > > > > > cookie, use HTTP_Client. Get the response back and search for some > > > > > phrase in it (using strstr()) that means that the login failed. > > > > > > > > > Yes I've read that package (you suggested to me two days ago) > > > > but found it hard to figure out how to use it. There's no adequate > > > > documents, and I am new to use pear...Anyway I will try again to > > > > understand it...If you can segguest me an example that will be great > > > > helpful.. Thanks! > > > > > > > > > > require_once('HTTP/Client.php'); > > > $client = new HTTP_Client(); > > > > > > $client->post('http://www.example.com/login.php', > > > array('username' => > > > 'user', 'password' => 'pass')); > > > $resp = $client->currentResponse(); > > > if(strstr($resp['body'], 'failed')) { > > > die('Login failed'); > > > } > > > > > > $client->get('http://www.example.com/restricted/page.php'); > > > $resp = $client->currentResponse(); > > > echo $resp['body']; > > > > > > > Many thanks to you for the example, it is great helpful! > > However, I found with HTTP_Request how to get the redirected > > location, here is how: > > $location = $req->_response->_headers['Location']; > > ($req is a $HTTP_Request object). > > > > Actually the $_response->_headers has already include enough > > information... > > So, to my understanding, php pear is something similar to the > > mod_perl:) > > > > Alex > > I was stupid :( > $req->getResponseHeader() can get all the header info. > > Alex > If you use HTTP_Client, it can do the redirection for you. -- DB_DataObject_FormBuilder - The database at your fingertips http://pear.php.net/package/DB_DataObject_FormBuilder paperCrane --Justin Patrin--

« previous php.pear.general (#13821) next »