16

within PHP (XAMPP) installed on a Windows XP Computer Im trying to read a dir which exists on a local network server. Im using is_dir() to check whether it is a dir that I can read.

In Windows Explorer I type \\\server\dir and that dir is being shown. When I map a network drive a can access it with z:\dir as well.

In PHP I have that script:

<?php if( is_dir($dir){ echo 'success' } ) ?>

For $dir I tried:

  • /server/dir
  • //server/dir
  • \server\dir
  • \\server\dir
  • \\\\server\\dir

and

  • z:\dir
  • z:\\dir
  • z:/dir
  • z://dir

But I never get success? Any idea? thx

Gumbo
  • 643,351
  • 109
  • 780
  • 844
Max
  • 1,143
  • 3
  • 15
  • 21

4 Answers4

10

I solved it by changing some stuff in the registry of the server as explained in the last answer of this discussion:

http://bugs.php.net/bug.php?id=25805

Thanks to VolkerK and Gumbo anyway! I love stackoverflow and their great people who help you so incredibly fast!!

EDIT (taken from php.net):

The service has limited access to network resources, such as shares and pipes, because it has no credentials and must connect using a null session. The following registry key contains the NullSessionPipes and NullSessionShares values, which are used to specify the pipes and shares to which null sessions may connect: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters Alternatively, you could add the REG_DWORD value RestrictNullSessAccess to the key and set it to 0 to allow all null sessions to access all pipes and shares created on that machine.`

add RestrictNullSessAccess=0 to your registery.

Max
  • 1,143
  • 3
  • 15
  • 21
  • 1
    This is true for Windows Server 2003. For Windows XP ensure the Local Security Policy settings "Network access: Let Everyone permissions apply to anonymous users" is set to Enabled. – Max May 27 '11 at 14:22
  • 3
    What would some of that stuff be? The link to php.net wasn't very helpful. Can you consolidate your solution here? – Wes Nov 06 '12 at 21:20
  • What if we can't touch the server. Is there a solution? – Scott Chu Oct 11 '16 at 02:15
9

You probably let xampp install apache as service and run the php scripts trough this apache. And the apache service (running as localsystem) is not allowed to access the network the way your user account is.

A service that runs in the context of the LocalSystem account inherits the security context of the SCM. The user SID is created from the SECURITY_LOCAL_SYSTEM_RID value. The account is not associated with any logged-on user account.
This has several implications:
...
   * The service presents the computer's credentials to remote servers.
...

You can test this by starting the apache as console application (apache_start.bat in the xampp directory should do that) and run the script again. You can use both forward and backward slashes in the unc path. I'd suggest using //server/share since php doesn't care about / in string literals.

<?php
$uncpath = '//server/dir';
$dh = opendir($uncpath);
echo "<pre>\n";
var_dump($dh, error_get_last());
echo  "\n</pre>";
Community
  • 1
  • 1
VolkerK
  • 95,432
  • 20
  • 163
  • 226
3

Try the file: URI scheme:

file://server/dir
file:///Z:/dir

The begin is always file://. The next path segment is the server. If it’s on your local machine, leave it blank (see second example). See also File URIs in Windows.

Gumbo
  • 643,351
  • 109
  • 780
  • 844
  • thanks for ur answer, gumbo! Unfortunately both solutions didn't work. is_dir() alsways returns false. PS: on a local dir (in example c:/dir) it returns true! – Max Jul 20 '09 at 14:36
  • Did you try that path in your Windows Explorer? It should work there too. – Gumbo Jul 20 '09 at 15:03
0

Yes, I know this is an old post, but I still found it, and if anyone else does... On Windows, with newer servers, verify the SMB is installed and enabled on the target machine.

Jams
  • 11
  • 3