0

I have had this problem for some time. I have set up a Windows IIS. But I would like to read the Windows username of the person who calls the page.

On other sites there is as solution: $_SERVER['REMOTE_USER']; But this did not work for me. I guess because the user who calls the page is an anonymous user. As an idea to solve this, I turned on authentication in Windows IIS Manager. IIS-Manager Authentication

But that didn't solve my problem either. My question now is: Does anyone have an idea how I could solve this problem?

Teemu
  • 22,918
  • 7
  • 53
  • 106
  • https://stackoverflow.com/questions/3899643/how-to-read-windows-logged-in-username-with-php-iis gives some alternative values which may give the information you are after. – Nigel Ren Feb 25 '21 at 07:46
  • $_SERVER['LOGON_USER'] $_SERVER['AUTH_USER'] $_SERVER['REDIRECT_LOGON_USER'] $_SERVER['REDIRECT_AUTH_USER'] I tried thoose to but it didn't work either :c – WoLBoss1 Feb 25 '21 at 07:49

2 Answers2

0

Yes there is a way to do this.

Since you are using Windows IIS you should be able to use this exec() command.

exec("wmic /node:$_SERVER[REMOTE_ADDR] COMPUTERSYSTEM Get UserName", $user);
echo($user[1]);

I got this answer from this question here.

I tested it out on my windows machine locally, and it worked like a charm for me.

Tim
  • 358
  • 2
  • 7
  • Rather than just copy an answer from another question, you should post a comment that this is a duplicate. – Nigel Ren Feb 25 '21 at 07:58
  • Hello Tim, Thanks for your answer. I now wrote in my php file: `
    ` But when I load the page, nothing shows up :c
    – WoLBoss1 Feb 25 '21 at 08:03
0

for me worked:

<?php
$username = gethostbyaddr($_SERVER['REMOTE_ADDR']);     
echo($username);
?> 
  • 1
    While this code may provide a solution to the question, it's better to add context as to why/how it works. This can help future users learn and eventually apply that knowledge to their own code. You are also likely to have positive feedback/upvotes from users, when the code is explained. – Amit Verma Feb 25 '21 at 09:06