Re: HTTP_Client: samples?

From: Date: Fri, 04 Jun 2004 15:05:19 +0000
Subject: Re: HTTP_Client: samples?
References: 1 2 3  Groups: php.pear.general php.pear.general 
Request: Send a blank email to pear-general+get-12906@lists.php.net to get a copy of this message
Robert wrote:
Alexey Borzov schrieb:
Robert wrote:
someone can provide an example of how to correctly use the HTTP_Client class? I want to be able sending form data to a site and don't understand how to use the updateCookies function.
You usually don't use it directly.
What I have so far and works: require_once("../inc-php/head.php"); require_once 'HTTP/Client.php'; $data = array( "username" => $_SESSION["sUsername"], "password" => $_SESSION["sPw"], "redirect" => "", "login" => "Log In" );
$sUri    = $aMyGlobals["sHttpHost"]."/phpBB/login.php";
$client =& new HTTP_Client();
$code     =  $client->post($sUri, $data);
$response = $client->currentResponse(); echo $response['body']; Now I need to be able to store the cookies from login.php.
That's done automagically. Just use Client to request the page you want after this, you are considered logged in by the site.
I'm not sure if I understood the last phrase. I see that the browser doesn't store any cookies from login.php. And after clicking on any of the site's links I'll get redirected to login.php because the site doesn't consider me logged in. When I login manually then login.php stores a couple of cookies. You may take a look for yourself at www.robertrossi.de/tangueria.net. Just login with user: testfall, pw: testfall, and then click on "Forum". The page will show up with the user "testfall" logged in, but any page within the forum you chose next will show up with no user registered.
Ah, here's your problem. You're supposed to be using HTTP_Client in *one* script call to *simulate* a browser. If you set up a script to do the login, then go to another URL *in the same script* then it will work. I'm not sure why you're trying to do a redirection kind of thing from another site.... If you're set on doing it that way, try storing your HTTP_Client in your session. Here's the normal usage: $c = new HTTP_Client(); $c->post('http://example.com/login.php', array('username' => 'user', 'password' => 'pass')); $c->get('http://example.com/loggedInResource.php'); Here's with a session: session_start(); if(!isset($_SESSION['http_client'])) { $_SESSION['http_client'] = new HTTP_Client(); } $_SESSION['http_client']->post(....); -- paperCrane <Justin Patrin>

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