Hi!
I want to access a site that is protected using .htacess on a remote server.
The page that I get is a clickable list of log files that get added by the host daily. I cannot get ftp access to this directory, or else I would definitely do it that way. It's only http.
These file names are simply the date.csv (01012004.csv, 01022004.csv).
Since the process of downloading these files is tedious and long, I created a little php script to go and fetch them.
As it didn't seem to work, I made a little debugging script to see where the problem was:
here is the loop:
$filepref ="http://uname:thepword@www.thehost.com/mydir/filedir/";
// Fake the browser type
ini_set('user_agent','MSIE 4.0b2;');
while (diff_days($cdate,$edate)>=0) {
$thefile = $am . $ad . $ay . ".csv";
//do the file stuff
$filename = $filepref . $thefile;
echo("Going to read: $filename . <br>");
// open file
If ($fh = fopen($filename, "r"))
{
$i=0;
while (!feof($fh)) {
$cline = fgets($fh);
echo(" Reading line $i: value= $cline<br>");
if (ltrim($cline)!="") {
$contents .= $cline;
$i++;
}
}
fclose($fh);
}
else {
//$errors .= "Could not open file " . $thefile . "<br>";
echo(" -- Could not open file " . $thefile . "<br>");
}
//normalize next day
$showname = getnextday($am, $ad, $ay);
list($am,$ad,$ay) = split('-',$showname);
$cdate=normalizedate($am, $ad, $ay);
}
I get:
Going to read: [url]http://uname:thepass@www.thehost.co...ir/01012004.csv[/url] .
Warning: fopen(http://...@www.thehost.com/mydir/01012004.csv): failed to open stream: HTTP request failed! HTTP/1.1 401 Access Denied in /var/www/html/fetchfile.php on line 147
-- Could not open file 01012004.csv
When I copy and past the url in the location bar, it prompts me for the uname/pword again, which I type in exactly and then get access to the file.
I found out that the host is a Window 2000 Server running IIS with all the latest patches. They told me that they don't block anything on the machine.
I did find out that there is a "domain" that we can put into the Basic Authentication, is there a way to implement that in the fopen command?
Or Is there a way to make it send the .htaccess login and password twice in a row through the php script?