php绑定客户端mac地址的代码

  php编程中,获取到用户mac地址,就可以实现与客户电脑的绑定、防止垃圾注册等。

  一个非常简单的类,使用时只要实例化后直接打印它的macAddr属性即可。

  代码:

  class Getmac{

  var $result = array(); // 返回带有MAC地址的字串数组

  var $macAddr;

  /*构造*/

  function __construct($osType){

  switch ( strtolower($osType) ){

  case "unix": break;

  case "solaris": break;

  case "aix": break;

  case "linux": {

  $this->for_linux_os();

  }break;

  default: {

  $this->for_windows_os();

  }break;

  }

  $temp_array = array();

  foreach($this->result as $value){

  if(preg_match("/[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f]/i",$value,

  $temp_array ) ){

  $this->macAddr = $temp_array[0];

  break;

  }

  }

  unset($temp_array);

  return $this->macAddr;

  }

  /*linux系统中获取方法*/

  function for_linux_os(){

  @exec("ifconfig -a", $this->result);

  return $this->result;

  }

  /*win系统中的获取方法*/

  function for_windows_os(){

  @exec("ipconfig /all", $this->result);

  if ( $this->result ) {

  return $this->result;

  } else {

  $ipconfig = $_SERVER["WINDIR"]."\system32\ipconfig.exe";

  if(is_file($ipconfig)) {

  @exec($ipconfig." /all", $this->result);

  &bbsp; } else {

  @exec($_SERVER["WINDIR"]."\system\ipconfig.exe /all", $this->result);

  return $this->result;

  }

  }

  }

  }

  /*1.实现化类 2.直接访问它的macAddr属性*/

  $getMac = new Getmac(PHP_OS);

  echo $getMac->macAddr;

  ?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值