NYCPHP Meetup

NYPHP.org

[nycphp-talk] http authentication

csnyder chsnyder at gmail.com
Tue Oct 17 13:35:19 EDT 2006


On 10/17/06, Rob Notwicz <rob.notwicz at gmail.com> wrote:
> Hey all, I need to parse data from pages which are behind a login.  Does
> anyone know how to do this? I'm kind of unfamiliar with HTTP protocol and
> new to PHP, so anything at all will be helpful.
>
>  (there is an http_request function listed on php.net, but the entry is
> sparse and I can't find any example code for it)
>
>  thanks so much,
>     Rob


If it's straight-up HTTP authentication (the kind where a standard
dialog box pops up in the browser asking for a username and password),
you can probably access it using something like:

$data = file_get_contents(
"http://username:password@example.com/path/to/data" );

If it's session-based authentication that was implemented in php or
some other server-side language, you'll need to POST a login form,
capture the session identifier (usually a cookie), and pass it back to
the server with each request.

-- 
Chris Snyder
http://chxo.com/



More information about the talk mailing list