Thiago H. Pojda wrote:
Guys,
I have to access a WS that uses HTTP auth directly with PHP.
I've tried using the usual http://user:[EMAIL PROTECTED]/ but I couldn't get it
working. I believe it has something to do with the password containing a #
(can't change it) and the browser thinks it's an achor or something.
All I've seen were scripts to implement HTTP Auth in PHP, nothing about
actually logging in with PHP.
Is it possible to send the authentication headers the first time I access
the link? I could send all necessary headers to the page I'm trying to
access and retrieve it's content at once.
Thanks,
use the Authorization http header and create a stream context with it in:
<?php
$url = 'http://example.com/';
$user = 'user';
$pass = 'pass';
$key = base64_encode($user . ':' . $pass);
$headers = 'Authorization: Basic '. $key . "\r\n";
$contextOpts = array('http'=>array('header'=>$headers));
$context = stream_context_create($contextOpts);
$page = file_get_contents($url, false, $context);
print_r( $page );
?>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php