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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Include with username & password ?

Status
Not open for further replies.

Antonimo

Technical User
Jun 26, 2003
86
SE
I am using a php include to build a web page with content that is stored in other files.

One of the files I wish to use is located in a subdomain that is password protected by .htaccess

The result is that there is an error that includes, "failed to open stream: HTTP request failed! HTTP/1.1 401 Authorization Required in /home/httpd/vhosts/..."

Is there a way in which I can still use the php include and have the php include send the username and password in order to collect the contents of the file?

I am a novice when it comes to php - any help would be appreciated.
 
Are the including script and the included file both on the same machine? If so, using an include across the filesystem will bypass Apache and thus the .htaccess password requirements.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Hi sleipnir214,

I think they probably are, however it isn't working.

Here are the errors (I have substituted "domain.com" for the real domain):

Warning:
main(http://client.domain.com/inc/documents.inc): failed to open stream: HTTP request failed! HTTP/1.1 401 Authorization Required in /home/httpd/vhosts/domain.com/httpdocs/main.php on line 138

Warning:
main(): Failed opening 'http://client.domain.com/inc/documents.inc' for inclusion (include_path='.:/usr/share/pear') in /home/httpd/vhosts/domain.com/httpdocs/main.php on line 138


I am trying to get the included file "documents.inc" to be displayed within the page "main.php"

The file "main.php" is in the directory httpdocs within domain.com

The file "documents.inc" is in directory "inc/" which is in "httpdocs/" which is in the directory "subdomains/", at the same level as "httpdocs/" directory of domain.com

Does this make sense?
 
As Sleipnir said, includes via the filesystem aren't subject to .htacces. Try "include /home/httpd/vhosts/client.domain.com/httpdocs/inc/documents.inc" instead (or whatever the actual path is).

By including via http:// you're subject to .htaccess.

You could try "include as an option. I have no idea if that would work.
 
Hi lgarner,

Thanks for the post.

I tried both of your suggestions without any success.

When I removed the .htaccess and .htpasswd files from the directory, the include works perfectly.

Is there something wrong in the way in which I have written the .htaccess file?...

AuthUserFile /home/httpd/vhosts/domain.com/subdomains/client/httpdocs/clientname/.htpasswd
AuthGroupFile /dev/null
AuthType Basic
AuthName "Client Protected Area"

<Limit GET>
order allow,deny
allow from all

require user username
</Limit>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top