Re: Running PHP scripts as a different user

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



why don't you try runas in the exec() function ?

"Jason Barnett" <jasbarne@xxxxxxxxxxx> a écrit dans le message news:
20040429175645.40991.qmail@xxxxxxxxxxxxxxx
> It seems that several people have run into a problem where PHP did not
> have permission to access certain folders / files in Windows.  I have
> two solutions that I have tried on WinXP, if others could verify if this
> works on other Windows platforms this would be helpful.
>
>
>
> Solution #1:
> Use the function CACLS to grant PHP's user access to the file / folder
> and then return permissions to normal when finished.  To do this
> manually use
> 1. Start -> Run -> cmd
> 2. "CACLS somefile.ext /E /G youruser:F "
> 3. "c:\php5\php.exe -f yourphpfile.php"
> 3. "CACLS somefile.ext /E /D youruser"
>
> Since this is a shell command, I thought we could also do this from a
> php script.  Unfortunately, I couldn't get it to work?  Here's what I
> tried for those that want to give it a shot:
>
> function switchUserExec($absfile, $user = null, $permission = 'F', $php
> = 'C:/php5/php.exe') {
>    $absfile = escapeshellarg($absfile);
>    $user = escapeshellarg($user);
>    $permission = escapeshellarg($permission);
>    $php_cli = escapeshellarg($php_cli);
>    $com = getenv('ComSpec').' /C ';
>
>    exec("$com CACLS $absfile /E /G $user:$permission");
>    exec("$com $php -f $absfile", $result);
>    exec("$com CACLS $absfile /E /D $user");
>
>    return $result;
> }
>
>
>
>
>
> Solution #2 (suphp.bat):
>
> @ECHO OFF
> REM  This is an example batch file for Windows systems running php.
> REM  It should enable you to run PHP from the command line as any user
> REM  you specify.  The main reason I made this was to temporarily give
> REM  PHP permission to access files of a specific user.  Change these
> REM  lines to match the user and path info for your system
>
> SET "PHP=C:\php5\php-win.exe"
> SET "USER=someuser"
> SET "PHP_FILE=C:\path\to\somescript.php"
>
> REM  You *can* add the switch /savecred to save the password
> REM  and avoid retyping each time, not sure how secure this is?
> RUNAS /user:%USER% "%PHP% -f %PHP_FILE%"
> @ECHO ON

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux