我可以在PHP中获取客户端用户名吗? [英] Can i get the client username in PHP?

查看:64
本文介绍了我可以在PHP中获取客户端用户名吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在Intranet上运行此网站.它具有一个表单,并且填写了一些数据然后提交.现在,我也想获取用户的用户名,因此用户不必输入它.到目前为止,我尝试了 $ username = gethostbyaddr($ _ SERVER ['REMOTE_ADDR]); .这就像一种魅力,因为它为我提供了数据来源的计算机名称.但是,不同的用户可以登录到计算机,这就是为什么这无济于事.

So i am running this website on the intranet. It has a form and some data is filled out and then submitted. Now i also want to get the username of the user, so the user does not have to enter it. So far i tried $username = gethostbyaddr($_SERVER['REMOTE_ADDR]);. This works like a charm as it gives me the computer name of where the data came from. But different users can log into the machine, which is why this doesnt help.

为了更清楚地说明到目前为止的工作方式:ComputerA正在运行XAMPP服务器.我可以使用ComputerB连接到该网站,并且在提交数据时,我的sql服务器将ComputerB作为用户名.与ComputerC进行了相同的尝试,并且还显示了ComputerC.

To make it bit more clear on what has worked so far: ComputerA is running XAMPP server. I can connect to the website using ComputerB and when i submitted the data, my sql server has ComputerB as the username. Tried same with ComputerC and it showed ComputerC as well.

我正在寻找的是C:\ Users \(name)\ Desktop.我想知道那个名字是什么?另外,如果你们能告诉我一些更好的东西,这可以是独一无二的,那也很好.不必是名字.

What i am looking for is how C:\Users\(name)\Desktop. I want to know what that name is? Also, if you guys can tell me something better which can be unique, that is fine as well. It doesnt have to be the name.

推荐答案

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

(如果您的PHP服务器托管在非Windows计算机上,或者您的Linux主机具有通过其他工具扩展的wmic功能,则无法使用此功能

(This wouldn't work if your PHP server is hosted on a non-windows machine or your linux host has wmic capabilities extended via other tools)

这篇关于我可以在PHP中获取客户端用户名吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆