HTTP Authentication

The HTTP stream wrapper has no context options for HTTP authentication credentials. However, it is possible to include the credentials as part of the URL being accessed. See the example below. Note that credentials are not pre-encoded; this is handled transparently when the request is made. Also, note that this feature only works when Basic HTTP authentication is used; Digest authentication must be handled manually.

<?php
$response = file_get_contents(
'http://username:password@localhost.example'
);
?>

© HTTP Streams Wrapper — Web Scraping

>>> Back to TABLE OF CONTENTS <<<
Category: Article | Added by: Marsipan (30.08.2014)
Views: 341 | Rating: 0.0/0
Total comments: 0
avatar