Page 1 of 1

login to other site by sending post variables

Posted: Fri Oct 30, 2009 6:13 am
by wieweet
hey,

here is my problem: my school gave me a mail account for school-stuff use. they mail us importent information like changes to the timetable. now this stupid mail account oanly has a web interface. no imap or pop3/smtp. (and it's not looking like that is going to change soon)

i am trying to make a script that logs in to the page an than screen-scrapes the web interface so and then just formats it as an rss feed or something so my feedreader can notifig me if i have a mail.

the login page of the webmail is a php page and it uses POST to send the login data to the next page. is also sets a cookie that i wil need to acces the next page.

i found a methed HttpRequest::send ( void ) on the php.net manual but i don't get how it works and how i can acces the data it returns, can you help me with this.
and secondly normaly i can get the data form the page by using $data = file_get_contents($url); or loadHTMLFile($url); but it might not work becouse it wel need the cookie... is thare a way i can do this?

thanks in advance,

wieweet

Re: login to other site by sending post variables

Posted: Fri Oct 30, 2009 6:26 am
by arnaud
Try http://pear.php.net/package/HTTP_Request2/docs

it's simple and well documented. it supports POST requests with data and file uploads, basic and digest authentication, cookies, proxies, gzip and deflate encodings, monitoring the request progress with Observers... 8)

an ex:

Code: Select all

 
<?php
require_once 'HTTP/Request2.php';
 
$request = new HTTP_Request2('http://pear.php.net/', HTTP_Request2::METHOD_GET);
try {
    $response = $request->send();
    if (200 == $response->getStatus()) {
        echo $response->getBody();
    } else {
        echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
             $response->getReasonPhrase();
    }
} catch (HTTP_Request2_Exception $e) {
    echo 'Error: ' . $e->getMessage();
}
?>