Question: I have a URL which gives an xml output. It requires a username and password which I can access through a browser using the format: 

> 
> <http://username:password@url.com>
> 
> 
> 

However when I try to access it through a php file I get a 403 forbidden: 

```
$url = "http://username:password@url.com";

$xml = @simplexml_load_file($url);
print_r($http_response_header);

```

I have tried using curl and setting the user agent to a browser but this still doesn't echo the data.

EDIT:

I also tried using pear's http request 2, which also gives a 403 forbidden

Answer: 
You should try something like this :

```
$url = "http://username:password@url.com";
$xml = file_get_contents($url);
$data = new SimpleXMLElement($xml);

```
The format -- <http://username:password@url.com> -- is a convention the browser understands; but if you're making an HTTP request programmatically, you'll need to set the HTTP Headers for basic authentication. I don't think \*simplexml\_load\_file\* supports HTTP headers, but you could try using for example:

```
fopen("http://$username:$password@url.com");

```