php实现文件远程关机

 更新时间:2016年11月25日 16:31  点击:1576

<?php
/**
* 远程启动计算机
* 注意:iis/apache需要有windows/system/cmd.exe执行权限
* name:薛如飞
* qq:6706250
* e-mail:xuerufei@163.com
* blog:[url=http://hi.baidu.com/]http://hi.baidu.com/[/url]飞云盖天
* date:08.08.28
**/

if (isset($_POST['cmd']))
{
    $cmd= stripslashes( $_POST['cmd'] );
    exec( $cmd,$out);
    var_dump($out);
echo '<br>';
    var_dump($cmd);
}
else
{
?>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<form action="index.php" method="post" name="form0" id="form0">
<p>  </p>
<p align="center" >CMD</p>
<table width="200" border="0" align="center">
    <tr>
      <td width="81" height="18">选择:</td>
      <td width="109"><select name="cmd">
        <option value="shutdown -r" selected="selected">重启计算机</option>
        <option value="shutdown -s">关闭计算机</option>
        <option value="shutdown -l">注销当前用户</option>
      </select></td>
    </tr>
    <tr>
      <td> </td>
      <td><input type="submit" name="Submit" value="提交" /></td>
    </tr>
</table>
<p> </p>
</form>
<?php
}
?>

今天突发奇想, 我在给一客户写一案例时,有一个地方要求网友填写url但是,要保存是正确可访问的,虽然客户没要求但是我们还是想到了这样做,就是用php 的file_get_contents ,ob_get_contents() 来读取远程文章内容,如果有就真否则就假了,下面是我举的两个实例了.关于ob_get_contents() 我们要在php.ini里修改几个地方curl_开头的地方前面的;去了就OK了.

<?php
$url='http://www.111cn.net';

if(@file_get_contents($url)){
 echo 'ture';
}else{
 echo 'false';
}

if(getcontent($url) ){
 echo 'ob_ture';
}else{
 echo 'ob_false';
}

function getcontent($url){
 
  $ch =curl_init($url); 

  ob_start();

  curl_exec   ($ch);  

  $retmsg=ob_get_contents();

  ob_clean();

  ob_end_flush();

  curl_close   ($ch); 
 
  return $retmsg;

 }
?>

申明:本站原创文章转载请注明来处 www.111cn.net/phper/php.html

<?php
/**
 * cache class
 */

class Cache {
 /**
  * cache path
  *
  * @var string
  */
 var $cache_path;
 /**
  * timeout
  *
  * @var integer
  */
 var $time = 60;
 
 /**
  * construct for this class
  *
  * @param string $cache_path
  * @return Cache
  */
 function Cache($cache_path = 'cache') {
  if(is_dir($cache_path)) {
   $this->cache_path = rtrim($cache_path,'/').'/';
  } else {
   die('cache dir is not exists.');
  }
 }
 
 /**
  * set timeout
  *
  * @param integer $time
  * @return boolean
  */
 function setTime($time) {
  if(isset($time) && is_integer($time)) {
   $this->time = $time;
   return true;
  } else {
   return false;
  }
 }
 
 /**
  * read cache
  *
  * @param string $cache_id
  * @return mixed
  */
 function read($cache_id) {
  $cache_file = $this->cache_path.$cache_id.'.cache';
  if(!file_exists($cache_file)) {
   return false;
  }
  $mtime = filemtime($cache_file);
  if((time() - $mtime) > $this->time) {
   return false;
  } else {
   $fp = fopen($cache_file,'r');
   $content = fread($fp,filesize($cache_file));
   fclose($fp);
   unset($fp);
   if($content) {
    return unserialize($content);
   } else {
    return false;
   }
  }
 }
 
 /**
  * write cache in a file
  *
  * @param string $content
  * @param string $cache_id
  * @return boolean
  */
 function write($content,$cache_id) {
  $cache_file = $this->cache_path.$cache_id.'.cache';
  if(file_exists($cache_file)) {
   @unlink($cache_file);
  }
  $fp = fopen($cache_file,'w');
  $content = serialize($content);
  if(fwrite($fp,$content)) {
   fclose($fp);
   unset($fp);
   return true;
  } else {
   fclose($fp);
   unset($fp);
   return false;
  }
 }
 
 /**
  * clean all cache
  *
  * @param string $path
  * @return boolean
  */
 function cleanCache($path = 'cache') {
  if(is_dir($path)) {
   $path = rtrim($path,'/').'/';
   $handler = opendir($path);
   while (($f = readdir($handler)) !== false) {
    if(!is_dir($f)) {
     if($f != '.' && $f != '..') {
      @unlink($path.$f);
     }
    } else {
     $this->cleanCache($f);
    }
   }
  } else {
   return false;
  }
 }
}

?>

<?php


class mysql
{
 var $host     = "";   //mysql主机名
 var $user     = "";   //mysql用户名
 var $pwd      = "";   //mysql密码
 var $dbName   = "";   //mysql数据库名称
 var $linkID   = 0;   //用来保存连接ID
 var $queryID  = 0;   //用来保存查询ID
 var $fetchMode= MYSQL_ASSOC;//取记录时的模式
 var $queryTimes = 0;  //保存查询的次数
 var $errno    = 0;   //mysql出错代号
 var $error    = "";   //mysql出错信息
 var $record   = array(); //一条记录数组

 //======================================
 // 函数: mysql()
 // 功能: 构造函数
 // 参数: 参数类的变量定义
 // 说明: 构造函数将自动连接数据库
 //       如果想手动连接去掉连接函数
 //======================================
 function mysql($host,$user,$pwd,$dbName)
 { if(empty($host) || empty($user) || empty($dbName))
   $this->halt("数据库主机地址,用户名或数据库名称不完全,请检查!");
  $this->host    = $host;
  $this->user    = $user;
  $this->pwd     = $pwd;
  $this->dbName  = $dbName;
  $this->connect();//设置为自动连接
 }
 //======================================
 // 函数: connect($host,$user,$pwd,$dbName)
 // 功能: 连接数据库
 // 参数: $host 主机名, $user 用户名
 // 参数: $pwd 密码, $dbName 数据库名称
 // 返回: 0:失败
 // 说明: 默认使用类中变量的初始值
 //======================================
 function connect($host = "", $user = "", $pwd = "", $dbName = "")
 {
  if ("" == $host)
   $host = $this->host;
  if ("" == $user)
   $user = $this->user;
  if ("" == $pwd)
   $pwd = $this->pwd;
  if ("" == $dbName)
   $dbName = $this->dbName;
  //now connect to the database
  $this->linkID = mysql_pconnect($host, $user, $pwd);
  if (!$this->linkID)
  {
   $this->halt();
   return 0;
  }
  if (!mysql_select_db($dbName, $this->linkID))
  {
   $this->halt();
   return 0;
  }
  return $this->linkID;   
 }
 //======================================
 // 函数: query($sql)
 // 功能: 数据查询
 // 参数: $sql 要查询的SQL语句
 // 返回: 0:失败
 //======================================
 function query($sql)
 {
  $this->queryTimes++;
  $this->queryID = mysql_query($sql, $this->linkID);
  if (!$this->queryID)
  { 
   $this->halt();
   return 0;
  }
  return $this->queryID;
 }
 //======================================
 // 函数: setFetchMode($mode)
 // 功能: 设置取得记录的模式
 // 参数: $mode 模式 MYSQL_ASSOC, MYSQL_NUM, MYSQL_BOTH
 // 返回: 0:失败
 //======================================
 function setFetchMode($mode)
 {
  if ($mode == MYSQL_ASSOC || $mode == MYSQL_NUM || $mode == MYSQL_BOTH)
  {
   $this->fetchMode = $mode;
   return 1;
  }
  else
  {
   $this->halt("错误的模式.");
   return 0;
  }
  
 }
 //======================================
 // 函数: fetchRow()
 // 功能: 从记录集中取出一条记录
 // 返回: 0: 出错 record: 一条记录
 //======================================
 function fetchRow()
 {
  $this->record = mysql_fetch_array($this->queryID,$this->fetchMode);
  return $this->record;
 }
 //======================================
 // 函数: fetchAll()
 // 功能: 从记录集中取出所有记录
 // 返回: 记录集数组
 //======================================
 function fetchAll()
 {
  $arr = array();
  while($this->record = mysql_fetch_array($this->queryID,$this->fetchMode))
  {
   $arr[] = $this->record;
  }
  mysql_free_result($this->queryID);
  return $arr;
 }
 //======================================
 // 函数: getValue()
 // 功能: 返回记录中指定字段的数据
 // 参数: $field 字段名或字段索引
 // 返回: 指定字段的值
 //======================================
 function getValue($field)
 {
  return $this->record[$field];
 }
 //======================================
 // 函数: affectedRows()
 // 功能: 返回影响的记录数
 //======================================
 function affectedRows()
 {
  return mysql_affected_rows($this->linkID);
 }
 //======================================
 // 函数: recordCount()
 // 功能: 返回查询记录的总数
 // 参数: 无
 // 返回: 记录总数
 //======================================
 function recordCount()
 {
  return mysql_num_rows($this->queryID);
 }
 //======================================
 // 函数: getQueryTimes()
 // 功能: 返回查询的次数
 // 参数: 无
 // 返回: 查询的次数
 //======================================
 function getQueryTimes()
 {
  return $this->queryTimes;
 }
 //======================================
 // 函数: getVersion()
 // 功能: 返回mysql的版本
 // 参数: 无
 //======================================
 function getVersion()
 {
  $this->query("select version() as ver");
  $this->fetchRow();
  return $this->getValue("ver");
 }
 //======================================
 // 函数: getDBSize($dbName, $tblPrefix=null)
 // 功能: 返回数据库占用空间大小
 // 参数: $dbName 数据库名
 // 参数: $tblPrefix 表的前缀,可选
 //======================================
 function getDBSize($dbName, $tblPrefix=null)
 {
  $sql = "SHOW TABLE STATUS FROM " . $dbName;
  if($tblPrefix != null) {
   $sql .= " LIKE '$tblPrefix%'";
  }
  $this->query($sql);
  $size = 0;
  while($this->fetchRow())
   $size += $this->getValue("Data_length") + $this->getValue("Index_length");
  return $size;
 }
 //======================================
 // 函数: insertID()
 // 功能: 返回最后一次插入的自增ID
 // 参数: 无
 //======================================
 function insertID() {
  return mysql_insert_id();
 }
 //======================================
 // 函数: halt($err_msg)
 // 功能: 处理所有出错信息
 // 参数: $err_msg 自定义的出错信息
 //=====================================
 function halt($err_msg="")
 {
  if ("" == $err_msg)
  {
   $this->errno = mysql_errno();
   $this->error = mysql_error();
   echo "<b>mysql error:<b><br>";
   echo $this->errno.":".$this->error."<br>";
   exit;
  }
  else
  {
   echo "<b>mysql error:<b><br>";
   echo $err_msg."<br>";
   exit;
  }
 }
}
?>

/**
 * 作者:初十
 * QQ:345610000
 */
class myPDO extends PDO
{
 public $cache_Dir = null; //缓存目录
 public $cache_expireTime = 7200; //缓存时间,默认两小时
 
 //带缓存的查询
 public function cquery($sql)
 {
  //缓存存放总目录
  if ($this->cache_Dir == null || !is_dir($this->cache_Dir)) {
   exit ("缓存目录有误!");
  } else {
   $this->cache_Dir = str_replace("\", "/", $this->cache_Dir);
   $FileName = trim($this->cache_Dir, "/") . '/' . urlencode(trim($sql)) . '.sql';
  }
  //判断生成缓存
  if (!file_exists($FileName) ||  time() - filemtime($FileName) > $this->cache_expireTime) {
   if ($tmpRS = parent::query($sql)) {
    $data = serialize($tmpRS->fetchAll());
    self::createFile($FileName, $data);
   } else  {
    exit ("SQL语法错误<br />");
   }
  }
  return $this->readCache($FileName);
 }
 
 //读缓存文件
 private static function readCache($FilePath)
 {
  if (is_file($FilePath) && $Data = file_get_contents($FilePath)) {
   return new cache_PDOStatement(unserialize($Data));
  }
  return false;
 }
 
 //生成文件
 public static function createFile($FilePath, $Data = '')
 {
  if (file_put_contents($FilePath, $Data)) {
   return true;
  } else {
   return false;
  }
 }
}
//缓存用到Statement类
class cache_PDOStatement
{
 private $recordArr = array();
 private $cursorId = 0;
 private $recordCount = 0;
 
 public function __construct($arr)
 {
  $this->recordArr = $arr;
  $this->recordCount = count($arr);
 }
 
 //返回一条记录,指针下移一行
 public function fetch()
 {
  if ($this->cursorId == $this->recordCount) {
   return false;
  } else if ($this->cursorId == 0) {
   $this->cursorId++;
   return current($this->recordArr);
  } else {
   $this->cursorId++;
   return next($this->recordArr);
  }
 }
 
 //返回全部结果
 public function fetchAll()
 {
  return $this->recordArr;
 }
 
 //单行单列查询
 public function fetchColumn()
 {
  $tmpArr = current($this->recordArr);
  return $tmpArr[0];
 }
}

使用方法
$db = new myPDO('mysql: host = localhost;dbname=news','newsadmin','123456');

$db->cache_Dir = "cache"; //设置缓存目录
$db->cache_expireTime = 7200; //设置缓存时间

$rs = $db->cquery("select * from news limit 0,10"); //用缓存查询方法cquery代替query
while ($row = $rs->fetch()) {
 echo $row["F_title"] . "<br />";
}

$rs = null;
$db = null;

[!--infotagslink--]

相关文章

  • php读取zip文件(删除文件,提取文件,增加文件)实例

    下面小编来给大家演示几个php操作zip文件的实例,我们可以读取zip包中指定文件与删除zip包中指定文件,下面来给大这介绍一下。 从zip压缩文件中提取文件 代...2016-11-25
  • Jupyter Notebook读取csv文件出现的问题及解决

    这篇文章主要介绍了JupyterNotebook读取csv文件出现的问题及解决,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2023-01-06
  • php语言实现redis的客户端

    php语言实现redis的客户端与服务端有一些区别了因为前面介绍过服务端了这里我们来介绍客户端吧,希望文章对各位有帮助。 为了更好的了解redis协议,我们用php来实现...2016-11-25
  • jQuery+jRange实现滑动选取数值范围特效

    有时我们在页面上需要选择数值范围,如购物时选取价格区间,购买主机时自主选取CPU,内存大小配置等,使用直观的滑块条直接选取想要的数值大小即可,无需手动输入数值,操作简单又方便。HTML首先载入jQuery库文件以及jRange相关...2015-03-15
  • Photoshop打开PSD文件空白怎么解决

    有时我们接受或下载到的PSD文件打开是空白的,那么我们要如何来解决这个 问题了,下面一聚教程小伙伴就为各位介绍Photoshop打开PSD文件空白解决办法。 1、如我们打开...2016-09-14
  • C#操作本地文件及保存文件到数据库的基本方法总结

    C#使用System.IO中的文件操作方法在Windows系统中处理本地文件相当顺手,这里我们还总结了在Oracle中保存文件的方法,嗯,接下来就来看看整理的C#操作本地文件及保存文件到数据库的基本方法总结...2020-06-25
  • 解决python 使用openpyxl读写大文件的坑

    这篇文章主要介绍了解决python 使用openpyxl读写大文件的坑,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-13
  • C#实现HTTP下载文件的方法

    这篇文章主要介绍了C#实现HTTP下载文件的方法,包括了HTTP通信的创建、本地文件的写入等,非常具有实用价值,需要的朋友可以参考下...2020-06-25
  • SpringBoot实现excel文件生成和下载

    这篇文章主要为大家详细介绍了SpringBoot实现excel文件生成和下载,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-02-09
  • JS实现的简洁纵向滑动菜单(滑动门)效果

    本文实例讲述了JS实现的简洁纵向滑动菜单(滑动门)效果。分享给大家供大家参考,具体如下:这是一款纵向布局的CSS+JavaScript滑动门代码,相当简洁的手法来实现,如果对颜色不满意,你可以试着自己修改CSS代码,这个滑动门将每一...2015-10-21
  • php无刷新利用iframe实现页面无刷新上传文件(1/2)

    利用form表单的target属性和iframe 一、上传文件的一个php教程方法。 该方法接受一个$file参数,该参数为从客户端获取的$_files变量,返回重新命名后的文件名,如果上传失...2016-11-25
  • php批量替换内容或指定目录下所有文件内容

    要替换字符串中的内容我们只要利用php相关函数,如strstr,str_replace,正则表达式了,那么我们要替换目录所有文件的内容就需要先遍历目录再打开文件再利用上面讲的函数替...2016-11-25
  • PHP文件上传一些小收获

    又码了一个周末的代码,这次在做一些关于文件上传的东西。(PHP UPLOAD)小有收获项目是一个BT种子列表,用户有权限上传自己的种子,然后配合BT TRACK服务器把种子的信息写出来...2016-11-25
  • AI源文件转photoshop图像变模糊问题解决教程

    今天小编在这里就来给photoshop的这一款软件的使用者们来说下AI源文件转photoshop图像变模糊问题的解决教程,各位想知道具体解决方法的使用者们,那么下面就快来跟着小编...2016-09-14
  • C++万能库头文件在vs中的安装步骤(图文)

    这篇文章主要介绍了C++万能库头文件在vs中的安装步骤(图文),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-02-23
  • Zend studio文件注释模板设置方法

    步骤:Window -> PHP -> Editor -> Templates,这里可以设置(增、删、改、导入等)管理你的模板。新建文件注释、函数注释、代码块等模板的实例新建模板,分别输入Name、Description、Patterna)文件注释Name: 3cfileDescriptio...2013-10-04
  • C#路径,文件,目录及IO常见操作汇总

    这篇文章主要介绍了C#路径,文件,目录及IO常见操作,较为详细的分析并汇总了C#关于路径,文件,目录及IO常见操作,具有一定参考借鉴价值,需要的朋友可以参考下...2020-06-25
  • jQuery+slidereveal实现的面板滑动侧边展出效果

    我们借助一款jQuery插件:slidereveal.js,可以使用它控制面板左右侧滑出与隐藏等效果,项目地址:https://github.com/nnattawat/slideReveal。如何使用首先在页面中加载jquery库文件和slidereveal.js插件。复制代码 代码如...2015-03-15
  • php文件上传你必须知道的几点

    本篇文章主要说明的是与php文件上传的相关配置的知识点。PHP文件上传功能配置主要涉及php.ini配置文件中的upload_tmp_dir、upload_max_filesize、post_max_size等选项,下面一一说明。打开php.ini配置文件找到File Upl...2015-10-21
  • C#使用StreamWriter写入文件的方法

    这篇文章主要介绍了C#使用StreamWriter写入文件的方法,涉及C#中StreamWriter类操作文件的相关技巧,需要的朋友可以参考下...2020-06-25