I'm trying to connect to a network share (by it's UNC) from the browser, but am unable to.
If I run my script from the command line, everything is fine and I can access the share. I'm also able to navigate to it through Windows' file explorer, so I don't think there's anything wrong with my code, or the permissions for my Windows account.
My script looks like this:
$dir = '\\somepath';
if (is_dir($dir))
{
echo 'dir exists';
}
else
{
echo 'dir does not exist';
}
I also tried using DirectoryIterator($dir)
, but that throws this exception error:
PHP Warning: opendir(...): Access is denied. (code: 5)
Here's my setup:
- Windows Server 2008 R2
- IIS 7.5
- PHP 5.3.13
- Anonymous Authentication disabled
- Windows Authentication enabled
And I have these config settings in my php.ini:
cgi.force_redirect=0
cgi.fix_pathinfo=1
fastcgi.impersonate=1
To add to the confusion, I was able to connect through the browser under these scenarios:
1 - using system("net use "".$dir."" ".$pass." /user:".$user." /persistent:no>nul 2>&1");
But this requires hardcoding the user's Windows auth password, which I can't do.
2 - Setting fastcgi.impersonate=0
But this means the user would have to authenticate everytime they hit the script, which is unacceptable.
3 - Enabling Anonymous Authentication, disabling Windows Authentication, but I need Windows Auth enabled in order to know who's accessing the site.
I don't know if this has anything to do with my problem, but I get different values for $_SERVER['USERNAME']
when running my script from the browser and from command line.
Is this a permissions issue? Is there an authentication token that's not being passed along?
Edit
Mapping the share to a network drive isn't an option in this case, unfortunately.
See Question&Answers more detail:
os