php 读取MAC地址

 更新时间:2016年11月25日 16:30  点击:1499
很多朋友想用php或js获取客户端的MAC地址,我可告诉你这是不可能的,除网友权限设置非常底。

class GetMacAddr{   
  
       var $return_array = array(); // 返回带有MAC地址的字串数组   
       var $mac_addr;   
  
       function GetMacAddr($os_type){   
            switch ( strtolower($os_type) ){   
                     case "linux":   
                               $this->forLinux();   
                               break;   
                     case "solaris":   
                               break;   
                     case "unix":   
                               break;   
                     case "aix":   
                               break;   
                     default:   
                               $this->forWindows();   
                               break;   
  
            }   
  
              
            $temp_array = array();   
            foreach ( $this->return_array 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->mac_addr = $temp_array[0];   
                               break;   
                     }   
  
            }   
            unset($temp_array);   
            return $this->mac_addr;   
       }   
  
  
       function forWindows(){   
            @exec("ipconfig /all", $this->return_array);   
            if ( $this->return_array )   
                     return $this->return_array;   
            else{   
                     $ipconfig = $_SERVER["WINDIR"]."system32ipconfig.exe";   
                     if ( is_file($ipconfig) )   
                        @exec($ipconfig." /all", $this->return_array);   
                     else  
                        @exec($_SERVER["WINDIR"]."systemipconfig.exe /all", $this->return_array);   
                     return $this->return_array;   
            }   
       }   
  
  
  
       function forLinux(){   
            @exec("ifconfig -a", $this->return_array);   
            return $this->return_array;   
       }   
  
}   
//方法使用   
//$mac = new GetMacAddr(PHP_OS);   
//echo $mac->mac_addr;   

过滤器验证ip地址,是否合法。

定义和用法
该过滤器验证FILTER_VALIDATE_IP价值作为一个网址。

名称: “ validate_ip ”
身份证号码: 275
可能的旗帜:

<?php
$ip = "192.168.0.1";
if(!filter_var($ip, FILTER_VALIDATE_IP))
 {
 echo "IP is not valid";
 }
else
 {
 echo "IP is valid";
 }
?>
输出结果。
is is valid

PHP and AJAX Suggest

这个suggest是仿google的效果了,google总是走在世界的技术的前面啊,下面我们也来看看实例吧.

先看看html文件.

<form> 
First Name:
<input type="text" id="txt1"
onkeyup="showHint(this.value)">
</form>
<p>Suggestions: <span id="txtHint"></span></p>
下面用js文件的ajax文件来处理数据.
var xmlHttp;

function showHint(str)
{
if (str.length==0)
  { 
  document.getElementById("txtHint").innerHTML="";
  return;
  }
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  } 
var url="gethint.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
} 

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
 } 
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 // Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}
 
这个文件只是返回php处理的数据,而我们的php文件如下.
<?php
// Fill up array with names
$a[]="Anna";
$a[]="Brittany";
$a[]="Cinderella";
$a[]="Diana";
$a[]="Eva";
$a[]="Fiona";
$a[]="Gunda";
$a[]="Hege";
$a[]="Inga";
$a[]="Johanna";
$a[]="Kitty";
$a[]="Linda";
$a[]="Nina";
$a[]="Ophelia";
$a[]="Petunia";
$a[]="Amanda";
$a[]="Raquel";
$a[]="Cindy";
$a[]="Doris";
$a[]="Eve";
$a[]="Evita";
$a[]="Sunniva";
$a[]="Tove";
$a[]="Unni";
$a[]="Violet";
$a[]="Liza";
$a[]="Elizabeth";
$a[]="Ellen";
$a[]="Wenche";
$a[]="Vicky";
//get the q parameter from URL
$q=$_GET["q"];
//lookup all hints from array if length of q>0
if (strlen($q) > 0)
{
$hint="";
for($i=0; $i<count($a); $i++)
  {
  if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))
    {
    if ($hint=="")
      {
      $hint=$a[$i];
      }
    else
      {
      $hint=$hint." , ".$a[$i];
      }
    }
  }
}

//Set output to "no suggestion" if no hint were found
//or to the correct values
if ($hint == "")
{
$response="no suggestion";
}
else
{
$response=$hint;
}

//output the response
echo $response;
?>
好了我们的确suggest效果就完成了.

PHP FTP 函数使用教程

引进的PHP的FTP
该功能提供的FTP客户端访问文件服务器通过文件传输协议( FTP ) 。

该FTP函数是用来打开,登录名和密切的联系,以及上传,下载,重命名,删除和获取信息的文件从文件服务器。并不是所有的FTP功能将与每一个服务器或返回同样的结果。该FTP函数成为可与PHP 3 。

这些功能都是为了详细访问FTP服务器。如果你只希望阅读或写入文件在FTP服务器上,可以考虑使用包装的ftp://与文件的功能。 
 

安装
PHP的Windows版本内置了支持的FTP延长。因此, FTP函数将自动工作。

然而,如果您运行的是Linux版本的PHP中,你将不得不与编译PHP -启用-的F TP( P HP4中+ )或- wi th-的F T P(P H P3中)得到的F T P职能工作。 
 

PHP的FTP函数
PHP的:显示最早的PHP版本,支持的功能。
Function Description PHP
ftp_alloc() Allocates space for a file to be uploaded to the FTP server 5
ftp_cdup() Changes the current directory to the parent directory on the FTP server 3
ftp_chdir() Changes the current directory on the FTP server 3
ftp_chmod() Sets permissions on a file via FTP 5
ftp_close() Closes an FTP connection 4
ftp_connect() Opens an FTP connection 3
ftp_delete() Deletes a file on the FTP server 3
ftp_exec() Executes a program/command on the FTP server 4
ftp_fget() Downloads a file from the FTP server and saves it to an open file 3
ftp_fput() Uploads from an open file and saves it to a file on the FTP server 3
ftp_get_option() Returns runtime behaviors of the FTP connection 4
ftp_get() Downloads a file from the FTP server 3
ftp_login() Logs on to an FTP connection 3
ftp_mdtm() Returns the last modified time of a specified file 3
ftp_mkdir() Creates a new directory on the FTP server 3
ftp_nb_continue() Continues retrieving/sending a file (non-blocking) 4
ftp_nb_fget() Downloads a file from the FTP server and saves it to an open file (non-blocking) 4
ftp_nb_fput() Uploads from an open file and saves it to a file on the FTP server (non-blocking) 4
ftp_nb_get() Downloads a file from the FTP server (non-blocking) 4
ftp_nb_put() Uploads a file to the FTP server (non-blocking) 4
ftp_nlist() Lists the files in a specified directory on the FTP server 3
ftp_pasv() Turns passive mode on or off 3
ftp_put() Uploads a file to the FTP server 3
ftp_pwd() Returns the current directory name 3
ftp_quit() Alias of ftp_close() 3
ftp_raw() Sends a raw command to the FTP server 5
ftp_rawlist() Returns a detailed list of files in the specified directory 3
ftp_rename() Renames a file or directory on the FTP server 3
ftp_rmdir() Removes a directory on the FTP server 3
ftp_set_option() Sets runtime options for the FTP connection 4
ftp_site() Sends a SITE command to the server 3
ftp_size() Returns the size of the specified file 3
ftp_ssl_connect() Opens a secure SSL-FTP connection 4
ftp_systype() Returns the system type identifier of the FTP server 3


PHP FTP Constants

PHP: indicates the earliest version of PHP that supports the constant.

Constant Description PHP
FTP_ASCII   3
FTP_TEXT   3
FTP_BINARY   3
FTP_IMAGE   3
FTP_TIMEOUT_SEC   3
FTP_AUTOSEEK   4
FTP_AUTORESUME Determine resume position and start position for get and put requests automatically 4
FTP_FAILED Asynchronous transfer has failed 4
FTP_FINISHED Asynchronous transfer has finished 4
FTP_MOREDATA Asynchronous transfer is still active 4

PHP的zip 使用方法

在Zip文件功能可以让你阅读ZIP文件。


-------------------------------------------------- ------------------------------

安装
对于Zip文件的职能工作,您的服务器,这些图书馆必须安装:

该ZZIPlib库吉Draheim :下载ZZIPlib图书馆
邮编PELC的延伸:下载的Zip PELC延长
安装Linux系统

PHP的5 + :邮政编码职能和邮编图书馆默认情况下不启用的,必须从上面的联系。使用-w ith-拉链=方向配置选项,包括邮政编码的支持。

Windows系统下的安装

PHP的5 + :邮政编码职能默认情况下不启用,所以php_zip.dll和ZZIPlib图书馆必须从上面的连结。 php_zip.dll必须启用内部的php.ini 。

为了使任何PHP扩展, PHP的extension_dir设置(在php.ini文件)应设置的目录下的PHP扩展库的位置。例如extension_dir值是c : PHP的分机。


-------------------------------------------------- ------------------------------

PHP的Zip文件功能
PHP的:显示最早的PHP版本,支持的功能。

Function Description PHP
zip_close() Closes a ZIP file 4
zip_entry_close() Closes an entry in the ZIP file 4
zip_entry_compressedsize() Returns the compressed size of an entry in the ZIP file 4
zip_entry_compressionmethod() Returns the compression method of an entry in the ZIP file 4
zip_entry_filesize() Returns the actual file size of an entry in the ZIP file 4
zip_entry_name() Returns the name of an entry in the ZIP file 4
zip_entry_open() Opens an entry in the ZIP file for reading 4
zip_entry_read() Reads from an open entry in the ZIP file 4
zip_open() Opens a ZIP file 4
zip_read() Reads the next entry in a ZIP file 4

[!--infotagslink--]

相关文章