PHP getting in to a password protected directory
Posted: Thu Jul 13, 2006 11:21 am
I have site.com/folder password protected and I have files that I want php to get to and include. Is there a way to do this?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
$folder = getcwd()."/folder/";
$dir = opendir($folder);
while ($file = readdir($dir))
{
if ($file != "." && $file != "..")
{
$file_path = $folder.$file;
if (file_exists($file_path))
{
include $file_path;
}
}
}
closedir($dir);I have a directory password protected by .htpasswd and .htaccess... so how could I unlock it just for PHPdull1554 wrote:i've had a similar problem, im assuming that hes using apache, and hes passwording a dir like myself using .htaccess and .htpasswd
That type of password protection only applies to HTTP. PHP reads the filesystem so it won't even be asked to authenticate.tecktalkcm0391 wrote:I have a directory password protected by .htpasswd and .htaccess... so how could I unlock it just for PHPdull1554 wrote:i've had a similar problem, im assuming that hes using apache, and hes passwording a dir like myself using .htaccess and .htpasswd
Code: Select all
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.example.co.za/protected/recipient.php');
// Username and password, separated by a colon.
curl_setopt($ch, CURLOPT_USERPWD, 'iang:iang');
curl_exec($ch);
curl_close($ch);
?>tecktalkcm0391 wrote:Ah, I found something would this work?
Code: Select all
<?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://www.example.co.za/protected/recipient.php'); // Username and password, separated by a colon. curl_setopt($ch, CURLOPT_USERPWD, 'iang:iang'); curl_exec($ch); curl_close($ch); ?>
Well... perhaps. Why don't you try it instead of asking?Would that work to allow me to acess the files in the protected by .htaccess files...
Code: Select all
// start CURL
$ch = curl_init();
// SET URL
curl_setopt($ch, CURLOPT_URL, 'http://site.com/');
// Username and password, separated by a colon.
curl_setopt($ch, CURLOPT_USERPWD, 'username:password');
// Turns curl into a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// set to string
$str = curl_exec($ch);
// close CURL
curl_close($ch);