Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing a htaccess protected file with PHP

Status
Not open for further replies.

Dweezel

Technical User
Feb 12, 2004
428
GB
I'm trying to access a remote file that is htaccess password protected using the fopen command. I'm trying this syntax without success:

Code:
fopen("username:password@[URL unfurl="true"]http://www.domain.com/protectedDir/file.csv","r");[/URL]

I've searched around for solutions but I'm drawing a blank. Does anyone know of a way I can read a remote htaccess password protected file via PHP?

TIA
Chris
 
what messages are you receiving from the server?

have you tried with cUrl?

are you sure that the web server is configured to serve csv files?
 
Thanks for the reply jpadie.

Message from the server is as below:

Code:
Warning: fopen(username:password@[URL unfurl="true"]http://www.domain.com/protectedDir/file.csv)[/URL] [function.fopen]: failed to open stream: No such file or directory in /home/user/public_html/test.php on line 14

I've never used cUrl before, but will give it a go now.

The server is configured to serve CSV files, as when the htaccess is removed there are no problems. My client is insisting on the htaccess protection though so I need to find a solution. I'll give your cUrl suggestion a spin.

Many thanks,
Chris
 
I just found out what the problem is. My original syntax should have been as follows:

Code:
fopen("[URL unfurl="true"]http://username:password@domain.com/protectedDir/file.csv","r");[/URL]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top