phpsql-serverwindowsiis-7windows-authentication

IIS PHP connect to MSSQL using Windows Authentication


I'm new to PHP and have run into a rather simple yet annoying issue.

Here is the setup:

If the users navigate to http://iisservername/ and try to connect to the mssql server via the php scripts, they receive Login failed for user NT AUTHORITY\ANONYMOUS LOGON

My workaround has been to launch a cmd script on the IIS server that uses runas /profile /user:domain\user "c:\program files\internet explorer\iexplore.exe"

I create a runas line for each user in the cmd script and execute it.

Upon launch, it navigates to homepage, which is a keepalive.php script I made that opens a connect and then javascript refreshes the page every x amount of minute(s).

Surely there is a better way to do this, yes?


Solution

  • If you use sqlsrv_connect and are using IIS's built in authentication it should be handled for you with nothing more then:

    /* Specify the server and connection string attributes. */
    $serverName = "(local)";
    $connectionInfo = array("Database" => "AdventureWorks");
    /* Connect using Windows Authentication. */
    $conn = sqlsrv_connect($serverName, $connectionInfo);
    

    (example from: http://msdn.microsoft.com/en-us/library/cc296205%28v=sql.90%29.aspx)