Re: Question regarding HTTP_Request

From: Date: Fri, 23 Jul 2004 04:36:14 +0000
Subject: Re: Question regarding HTTP_Request
References: 1 2 3  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-13817@lists.php.net to get a copy of this message
On Fri, 23 Jul 2004 00:26:34 -0400, Alex Shi <chpshi@stonix.com> wrote: > > On Thu, 22 Jul 2004 23:59:32 -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']; -- DB_DataObject_FormBuilder - The database at your fingertips http://pear.php.net/package/DB_DataObject_FormBuilder paperCrane --Justin Patrin--

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