0

I have scripts that use the $_SERVER["LOGON_USER"] which is obtained on my servers through IIS authentication settings. I want this same variable to contain my domain\username when running locally, or at least to have a way to set it when I fire up the PHP built-in server on localhost.

How can I configure PHP on my machine to obtain and fill this variable the same way it does when running through IIS?

PS: I have seen this question, but the answer addresses $_ENV, not $_SERVER.

Marcos Dimitrio
  • 6,651
  • 5
  • 38
  • 62

1 Answers1

0

This is a workaround, if anyone has a better/proper solution (i.e. enabling NTLM), please post it as an answer and I'll accept it.

I was able to fill that variable using a router script. According to the docs, this script is run at the start of each HTTP request, so I use it to set this variable when running locally.

Also in my case, my environment had these two variables set, USERDOMAIN and USERNAME, so I used them to form the LOGON_USER server variable.

routerCredentials.php

<?php
$_SERVER["LOGON_USER"] = getenv("USERDOMAIN") . "\\" . getenv("USERNAME");
return false; // serve the requested resource as-is.

To use it, you just have to point to that file when you start the PHP built-in server:

php -S localhost:8000 "c:\somepath\routerCredentials.php"
Marcos Dimitrio
  • 6,651
  • 5
  • 38
  • 62