Hi,
I have a problem with reading a secured remote file.I mean for reading a file required username && password..
I tried it this way..
$hange = fopen('http://username:password@www.fragrancen ... 2.txt','rt');
But is showing
failed to open stream: HTTP request failed! HTTP/1.1 401 Authorization Required
help regarding this problem would be great
remote secured file reading in php
Moderator: General Moderators
Re: remote secured file reading in php
You sure you have the right file location? When I go to http://www.fragrancenet-wholesale.com/datafeed2.txt I'm redirected to http://www.fragrancenet.com/datafeed2.txt and that gives me a 404 page.
Re: remote secured file reading in php
Use cURL instead. Otherwise you should implement HTTP authentication on your own, and cURL already support it...
Code: Select all
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);Re: remote secured file reading in php
can you give some example...
Re: remote secured file reading in php
Code: Select all
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
$response = curl_exec($ch);
if ($response === false) {
$error = curl_error($ch);
curl_close($ch);
die($error);
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode && $httpCode != 200) {
curl_close($ch);
die('Response code ' . $httpCode);
}
curl_close($ch);
echo $response;