用JS获取了MAC地址后怎么输出
网上找了一段JS代码,点按钮可以获取MAC地址,但后面的PHP只能输出字符串,输出不了mac地址呢?该怎么调用这个变量呢,代码是这样的:<head><metahttp-e...
网上找了一段JS代码,点按钮可以获取MAC地址,但后面的PHP只能输出字符串,输出不了mac地址呢?该怎么调用这个变量呢,代码是这样的:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
<title>js获取mac地址</title>
<SCRIPT language="JavaScript">
function MacInfo(){
var locator =new ActiveXObject ("WbemScripting.SWbemLocator");
var service = locator.ConnectServer(".");
var properties = service.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled =True");
var e =new Enumerator (properties);
{
var p = e.item();
var mac = p.MACAddress;
alert(mac)
}
}
</SCRIPT>
<body>
<input type="button" onclick="MacInfo()"/>
</body>
</html>
<?php
echo mac;
echo $mac;
?> 展开
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
<title>js获取mac地址</title>
<SCRIPT language="JavaScript">
function MacInfo(){
var locator =new ActiveXObject ("WbemScripting.SWbemLocator");
var service = locator.ConnectServer(".");
var properties = service.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled =True");
var e =new Enumerator (properties);
{
var p = e.item();
var mac = p.MACAddress;
alert(mac)
}
}
</SCRIPT>
<body>
<input type="button" onclick="MacInfo()"/>
</body>
</html>
<?php
echo mac;
echo $mac;
?> 展开
1个回答
展开全部
我也是醉了,😓
js中定义的变量是在浏览器端定义的
php中的变量是服务端定义的
你服务器上怎么可能访问到浏览器端的变量
建议你复习一下B/S网络结构
如果你要展示到页面上MAC地址,你只能用浏览器端去访问
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
<title>js获取mac地址</title>
<SCRIPT language="JavaScript">
function MacInfo(){
var locator =new ActiveXObject ("WbemScripting.SWbemLocator");
var service = locator.ConnectServer(".");
var properties = service.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled =True");
var e =new Enumerator (properties);
{
var p = e.item();
var mac = p.MACAddress;
document.writeln('<p>' + mac + '</p>');
}
}
</SCRIPT>
<body>
<input type="button" onclick="MacInfo()"/>
</body>
</html>
追问
好吧,让您见笑了。我也是初次接触这东西,我想要实现的是客户端网页打开网站时,服务端根据MAC地址的不同给客户端网页上指定的地方显示不同的字,不知道该怎么搞。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询