mysql数据抽象层-PDO

作者 : admin 于 2009年08月20日, 16:02:02
2009
08-20

好久不用PDO了,公司这边有的项目使用PDO,再熟悉一下,继续沿用之前的方法:

没用数据绑定和一些高级的功能,只是实现基础功能。

  1. < ?php
  2. interface DateBaseConnect
  3. {
  4. #数据库连接
  5. public function Connect( $host , $user , $pass , $datebase );
  6. #使用数据库
  7. public function selectDateBase( $datebase );
  8. #执行一个查询
  9. public function query( $sql );
  10. #取得一行
  11. public function fetch( $sql );
  12. #取得所有
  13. public function fetchAll( $sql );
  14. #取得影响行数
  15. public function affectedRow();
  16. #取得结果行数
  17. public function recordCount();
  18. #取得上次插入ID
  19. public function insertID();
  20. #释放资源
  21. public function close();
  22. }
  23. class sPDO implements DateBaseConnect
  24. {
  25. #连接标识
  26. public $handle = false;
  27. #结果标识
  28. public $query;
  29. #查询次数
  30. public $exetime;
  31. #影响行数
  32. public $affectedRows;
  33. #statement
  34. public $statement;
  35. #数据库连接
  36. public function Connect( $host , $user , $pass , $datebase )
  37. {
  38. try
  39. {
  40. $this->handle = new PDO("mysql:dbname=".$datebase.";host=".$host, $user, $pass);
  41. }
  42. catch (PDOException $e)
  43. {
  44.             echo 'Connection failed: ' . $e->getMessage();
  45. }
  46. $this->exetime = 0;
  47. }
  48. #选择数据库
  49. public function selectDateBase( $database )
  50. {
  51.     return true;
  52. }
  53. #执行一个查询
  54. public function query( $sql )
  55. {
  56.     $this->affectedRows = $this->handle->exec( $sql );
  57. $this->exetime++;
  58. return true;
  59. }
  60. #取得一行
  61. public function fetch( $sql )
  62. {
  63. $this->statement = $this->handle->query( $sql );
  64. return $this->statement->fetch(PDO::FETCH_ASSOC);
  65. }
  66. #取得所有
  67. public function fetchAll( $sql )
  68. {
  69. $this->statement = $this->handle->query( $sql );
  70. return $this->statement->fetchAll(PDO::FETCH_ASSOC);
  71. }
  72. #取得影响行数
  73. public function affectedRow()
  74. {
  75. return $this->affectedRows;
  76. }
  77. #取得结果行数
  78. public function recordCount()
  79. {
  80. return $this->statement->rowCount();
  81. }
  82. #取得上次插入ID
  83. public function insertID()
  84. {
  85. $sql = sprintf("SELECT LAST_INSERT_ID() AS id");
  86. $pdostatement = $this->handle->query( $sql );
  87. $rs = $pdostatement->fetch();
  88. return $rs['id'];
  89. }
  90. #释放资源
  91. public function close()
  92. {
  93. unset($this->handle);
  94. }
  95. #析构函数
  96. function __destruct()
  97. {
  98. $this->close();
  99. }
  100. }
  101. #Demo
  102. $db = new sPDO;
  103. $db->Connect( 'localhost' , 'root' , '123456' , 'ucenterhome' );
  104. $rs = $db->fetchAll( "SELECT * FROM uchome_blogfield" );
  105. print_r( $rs );
  106. ?>

对UCenter Home的一点看法

作者 : admin 于 2009年08月17日, 22:27:19
2009
08-17

最近改了改UCenter Home,发现,这的确是个不错的产品,但不能算一个成熟的程序。

产品看法:

这个产品主要是服务一些个人站长和小型站点,功能模仿一些成熟的sns系统,模仿比较到位,而且功能上尽可能大的去完善,让管理员可以方便进行比较系统全面的管理。而从产品的设计体验上,也能适应中国大多数的用户。

所以,这个产品在国内算一套非常不错的sns建站系统。

编码方面:

要说代码,我相信阅读过代码的人一定很头疼,从discuz的bbs就这样。

代码只是面向过程,这个,在discuz方面,我估计是累积开发造成的,一个个版本升级,变化不能太大,如果变化真的太大,会失去一些开发者。另外,他自己升级也是个问题。

不过uch这个产品也开发成了这样。代码结构我倒挺喜欢,之前我写那个架子也是这样。优点:结构规范,适合多人协作。缺点,面向对象性,代码复用差。这个结构,我估计是公司某元老折腾的,然后有几个小弟进行模块开发。

为什么这么说,是有原因的,因为遍历整个代码,起码有两种以上的代码风格,而且人员之间沟通配合也造成了一些错误,虽然不是bug,但看得出来项目进行的仓促。不过这也是公司的一个战略措施,小戴同学总是及时放出产品来打压竞争对手。

再说负载,其实这个问题就不用说,从大量的垃圾sql语句就能看出,这个产品不能支持较大的负载。

再说最后一点,如果你想去优化改善,彻底改善,放弃吧。重写。

我看的只是uch2.0的预览版,估计正式版放出的时候,这些问题会有所改善。

Discuz一些乱码错误的总结

作者 : admin 于 2009年08月03日, 22:19:12
2009
08-3

最近用Discuz6.0,在用到分类信息功能的时候,自建模板总是出现错误,仔细跟踪,发现是个别模板编码错误。我用的UTF-8版本,有不少文件里用了中文字符,而且是gbk编码,造成了这种错误。

我google此类信息,有不少问题都出现在了编码上,建议网友在使用的时候,发现编码错误,仔细跟踪一下,找出模板。大部分的问题基本能以此方式解决。

smarty分页程序,模板小改进

作者 : admin 于 2009年07月27日, 15:11:04
2009
07-27

增加了:跳转到第几页的功能

模板部分

  1. <div id="page">
  2. <table>
  3.     <tr>
  4.     <td>
  5. 共{{$page.count}}条数据 每页{{$page.pagesize}}条  共{{$page.pagecount}}页 当前第{{$page.page}}页
  6.                 <!-- 新加的跳转功能  start -->
  7.                 跳转到第
  8.                 <select onchange="window.location.href='{{$page.baseurl}}&page='+this.options[this.selectedIndex].value">
  9.                 {{section name=pagejump loop=4 start=0 step=1 max=4}}
  10.                 <option value="{{$smarty.section.pagejump.index+1}}">{{$smarty.section.pagejump.index+1}}</option>
  11.                 {{/section}}
  12.                 </select> 页
  13.                 <!-- 新加的跳转功能  start -->
  14. </td>
  15. <td>
  16. {{if $page.pagecount>1}}
  17. {{if $page.first eq 1}}
  18. <a href="{{$page.baseurl}}">首页</a>
  19. {{else}}
  20. 首页
  21. {{/if}}
  22. {{if $page.pre eq 1}}
  23. <a href="{{$page.baseurl}}&page={{$page.page-1}}">上一页</a>
  24. {{else}}
  25. 上一页
  26. {{/if}}
  27. {{foreach from=$page.pagelist item=vols}}
  28.     {{if ($vols.page > 0 ) && ($vols.page < = $page.pagecount) }}
  29. {{if $vols.link eq 1}}
  30. <a href="{{$page.baseurl}}&page={{$vols.page}}">[{{$vols.page}}]
  31. {{else}}
  32. [{{$vols.page}}]
  33. {{/if}}
  34. {{/if}}
  35. {{/foreach}}
  36. {{if $page.next eq 1}}
  37. <a href="{{$page.baseurl|default:"?"}}&page={{$page.page+1}}">下一页</a>
  38. {{else}}
  39. 下一页
  40. {{/if}}
  41. {{if $page.last eq 1}}
  42. <a href="{{$page.baseurl|default:"?"}}&page={{$page.pagecount}}">尾页</a>
  43. {{else}}
  44. 尾页
  45. {{/if}}
  46. {{/if}}
  47. </td>
  48. </tr>
  49. </table>
  50. </div>

其实我在做的时候又出现个问题,如果是url重写了,如何来做这个baseurl变量。问题解决方法是,把url当做模板,比如/blog/index/%d

使用成语的文字验证码

作者 : admin 于 2009年07月24日, 21:48:44
2009
07-24

上次写的nb验证码程序,遭到了大部分人的唾弃,因为我使用了中国汉字全集,而大部分中国人对汉字了解还只能占其一半,也就是四个汉字中经常出现生僻字,造成无法使用。

这次使用成语作为汉字验证码(其实已经发现其他网站再用),则中文用户识别的几率就大得多。

demo:

程序下载:点击下载

图片动态缩放PHP与JS算法

作者 : admin 于 2009年07月20日, 08:19:05
2009
07-20

这个算法写好多次了,虽然简单,但每次都得想一次,这里做个备份。

因为GD函数进行缩放,必须有宽和高,而在浏览器中,会自动按照比率调整宽高,所以两个函数稍有区别。

  1. #PHP版
  2. # $s_width  原图宽
  3. # $s_height 原图高
  4. # $t_width  目标文件最大宽
  5. # $t_height 目标文件最大高
  6. function ReSizePic( $s_width , $s_height , $t_width , $t_height)
  7. {
  8. if( $s_width / $s_height > $t_width / $t_height && $s_width > $t_width)
  9. {
  10. $t_height = $s_height * $t_width / $s_width;
  11. $t_width = $t_width;
  12. }
  13. else if( $s_width / $s_height > $t_width / $t_height && $s_width < = $t_width)
  14. {
  15. $t_height = $s_height;
  16. $t_width  = $s_width;
  17. }
  18. else if( $s_width / $s_height < $t_width / $t_height && $s_height > $t_height)
  19. {
  20. $t_width = $s_width*$t_height/$s_height;
  21. $t_height = $t_height;
  22. }
  23. else if( $s_width / $s_height < $t_width / $t_height && $s_height <= $t_height)
  24. {
  25. $t_height = $s_height;
  26. $t_width  = $s_width;
  27. }
  28. return array( "width" => $t_width , "height" => $t_height );
  29. }
  30. #JS版
  31. # obj 图片对象
  32. # maxWidth 显示最大宽
  33. # maxHeight 显示最大高
  34. function ReSizePic( obj , maxWidth , maxHeight )
  35. {
  36. if( ( obj.width/obj.height >= maxWidth/maxHeight ) && obj.width > maxWidth )
  37. {
  38. obj.width = maxWidth;
  39. }
  40. else if( ( obj.width/obj.height < maxWidth/maxHeight ) && obj.height > maxHeight )
  41. {
  42. obj.height = maxHeight;
  43. }
  44. }

为FCKEditor增加图片附件管理功能

作者 : admin 于 2009年07月15日, 13:38:10
2009
07-15

其实好久没用过FCKEeditor了,因为将近两年没写过CMS,今天突然人品大爆发,想起了这个问题。

fckeditor是一个非常棒的所见即所得在线编辑器,包括一些门户网站都在使用。fckeditor有个问题,就是上传图片默认为一个文件夹,当然这个问题早已经解决,我们可以用cookie或者session的方式给参数 $Config['UserFilesPath'] 就可以定制上传路径。而后在文章保存的过程中即可保存图片地址。

然后在使用过程中又出现一个问题,虽然我们知道图片在哪个文件夹,但我们却不能动态的去知道具体文件夹内有哪几个图片,预览是什么。而且,我们在写CMS的时候经常需要调用其中一张图片做封面,原来的机制显然无法去满足这些需求(当然你也可以查看编辑器内的源代码来查看图片地址,不过对于外行似乎有点困难)。

突然看到了discuz的附件机制,相出这么个损招:每张图片上传都给他存储在数据库中,打上guid(或者唯一的地址)进行标识,当我们保存的时候,图片会跟文章关联,在使用之前还可以用ajax动态调用预览,可谓一举两得。

文章保存后,图片进入数据库,另外还可以方便找出编辑遗留的垃圾,因为很多时候一个已经传了文章的草稿没有保存,而遗留很多的临时文件。

最近的fck版本好像升级了,配置文件放从根目录迁移了,不过fck代码非常规整,做这么个改造不是很难,就没写demo。

———————————————-

文章很冗余,骗稿费?

PHP开发的一个pureftpd管理工具

作者 : admin 于 2009年07月10日, 16:49:14
2009
07-10

用过pureftpd manager,虽然功能足够,但很多bug,无法使用,而pureftpd功能简单,写个管理工具也没多复杂,于是乎,花两个晚上写了个简单的管理脚本,分享给大家。不过没来得及写注释,回头会把注释补上。

分流下载 http://down.chinaz.com/soft/26439.htm

点击下载

  1. < ?php
  2. error_reporting(2047);
  3. header("Content-Type: text/html; charset=utf-8");
  4. header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
  5. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // 过去的时间
  6. define("FILENAME",$_SERVER['PHP_SELF']);
  7. $adminuser = "admin";
  8. $adminpass = "admin";
  9.  
  10. $servtype = 'mysql';
  11. $hostname = 'localhost';
  12. $username = 'root';
  13. $password = '123456';
  14. $datebase = 'pure-ftpd';
  15. $table    = "users";
  16. $charset  = 'utf8';
  17. $crypt    = "MD5";
  18.  
  19. session_start();
  20. #session_destroy();
  21. $action = isset($_GET['action']) ? $_GET['action'] : "index";
  22.  
  23.  
  24. switch( $action )
  25. {
  26.     case "index":
  27.     checklogin();
  28. func_html( 0 );
  29. switch($_SESSION['user'])
  30. {
  31.     case $adminuser:
  32.     func_admin_index();
  33. break;
  34. default:
  35.     func_user_index();
  36. break;
  37. }
  38. func_html( 1 );
  39. break;
  40.     case "userlogin":
  41. case "adminlogin":
  42.     func_html( 0 );
  43.     func_userlogin();
  44. func_html( 1 );
  45. break;
  46. case "userloginaction":
  47.     func_userloginaction( $_POST['username'] , $_POST['password'] , $_POST['logintype'] );
  48. break;
  49. case "userpasswordchang":
  50.     checklogin();
  51. user_password_chang( $_POST['password'] );
  52. break;
  53. case "adminchangeuserpassword":
  54. case "useradd":
  55.     checklogin(true);
  56. func_admin_user_edit( isset($_GET['user']) ? $_GET['user'] : false );
  57. break;
  58. case "userinfoac":
  59.     checklogin(true);
  60. switch($_POST['action'])
  61. {
  62.     case "edit":
  63.     func_admin_useredit();
  64. break;
  65. case "add":
  66.     func_admin_useradd();
  67. break;
  68. }
  69. break;
  70. case "adminuserdel":
  71.     func_user_del( $_GET['user'] );
  72. break;
  73. case "logout":
  74.     func_logout();
  75. break;
  76. }
  77.  
  78.  
  79. function func_html( $position = 0 )
  80. {
  81.     switch( $position )
  82. {
  83.     case 0:
  84.     echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
  85. <html xmlns=\"http://www.w3.org/1999/xhtml\">
  86. <head>
  87. <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
  88. <title>PURE-FTPD简易管理系统</title>
  89. <style type=\"text/css\">
  90. td
  91. {
  92. padding:4px;
  93. }
  94. .bar
  95. {
  96.     width:80%;
  97. border-bottom:dotted 1px #aaa;
  98. margin-bottom:20px;
  99. padding:10px;
  100. }
  101. </style>
  102. </head>
  103. <body>
  104. <div class=\"bar\">PURE-FTPD简易管理工具 &nbsp; 孙博宇 &nbsp; http://www.sunboyu.cn &nbsp; QQ:176300676 &nbsp; MSN:sunboyu@gmail.com  &nbsp; ";
  105. if(isset($_SESSION['user']))
  106. {
  107.     echo "<input type=\"button\" name=\"logout\" id=\"logout\" value=\"退出\"  onclick=\"window.location.href='?action=logout'\" />";
  108. }
  109. echo "</div>";
  110. break;
  111. case 1:
  112.     echo "</body>
  113. </html>
  114. ";
  115. break;
  116. }
  117.     
  118. }
  119. function checklogin( $type = false )
  120. {
  121.     global $adminuser;
  122.     if(!isset($_SESSION['user']))
  123. {
  124. header("Location:".FILENAME."?action=userlogin");
  125. }
  126. if($type&&$_SESSION['user']!=$adminuser)
  127. {
  128.     header("Location:".FILENAME."?action=adminlogin");
  129. }
  130. }
  131.  
  132. function func_userlogin( )
  133. {
  134.     echo "<form name=\"loginform\" id=\"loginform\" action=\"?action=userloginaction\" method=\"post\">
  135. <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"margin:0px;\">
  136. <tr>
  137. <td colspan=\"2\" align=\"center\">用户登录</td>
  138. </tr>
  139. <tr>
  140. <td width=\"60\" align=\"right\">用户名</td><td width=\"200\"><input type=\"text\" name=\"username\" id=\"username\" /></td>
  141. </tr>
  142. <tr>
  143. <td align=\"right\">密码</td><td><input type=\"password\" name=\"password\" id=\"password\" /></td>
  144. </tr>
  145. <tr>
  146. <td align=\"center\" colspan=\"2\"><input type=\"submit\" name=\"submit\" id=\"submit\" value=\"登录\" /><input type=\"hidden\" name=\"logintype\" id=\"logintype\" value=\"{$_GET['action']}\" /> &nbsp; ";
  147. if($_GET['action']=="userlogin")
  148. {
  149.     echo "<a href=\"?action=adminlogin\">管理员登录</a>";
  150. }
  151. else
  152. {
  153.     echo "<a href=\"?action=userlogin\">用户登录</a>";
  154. }
  155. echo "</td>
  156. </tr>
  157. <tr>
  158. <td align=\"center\" colspan=\"2\">".(isset($_GET['error']) ? $_GET['error'] : "")."</td>
  159. </tr>
  160. </table>
  161. </form>
  162. ";
  163. }
  164.  
  165. function func_getdb()
  166. {
  167.     global $hostname,$username,$password,$datebase,$charset;
  168. $handle = @mysql_connect( $hostname , $username , $password , false ) or die("Can't connetc to the DateBse.".mysql_error());
  169. @mysql_select_db( $datebase , $handle ) or die("Can't select the DateBase".mysql_error());
  170. mysql_query( "SET NAMES '{$charset}'" , $handle );
  171. return $handle;
  172. }
  173.  
  174. function func_userloginaction( $usernames , $passwords , $logintype )
  175. {
  176.     switch( $logintype )
  177. {
  178.     case "userlogin":
  179.     global $table,$username,$password,$crypt;
  180. $handle = func_getdb();
  181. #echo "SELECT COUNT(*) AS count FROM {$table} WHERE User = '{$usernames}' AND Password = ".$crypt."('".$passwords."')";
  182. $query = mysql_query("SELECT COUNT(*) AS count FROM {$table} WHERE User = '{$usernames}' AND Password = ".$crypt."('".$passwords."')" , $handle);
  183. $row = mysql_fetch_array( $query, MYSQL_ASSOC );
  184. if($row['count']==1)
  185. {
  186. $_SESSION['user'] = $usernames;
  187. echo "登录成功,跳转中……";
  188. echo "<meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=index\">";
  189. }
  190. else
  191. {
  192. header("Location:".FILENAME."?action=userlogin&error=".urlencode("用户名或者密码错误!"));
  193. }
  194. break;
  195. case "adminlogin":
  196.     global $adminuser,$adminpass;
  197.     if($adminuser==$usernames&&$adminpass==$passwords)
  198. {
  199.     $_SESSION['user'] = $usernames;
  200. echo "登录成功,跳转中……";
  201. echo "</meta><meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=index\">";
  202. }
  203. else
  204. {
  205.     header("Location:".FILENAME."?action=adminlogin&error=".urlencode("用户名或者密码错误!"));
  206. }
  207. break;
  208. }
  209. }
  210.  
  211. function func_user_index()
  212. {
  213.     global $table,$username,$password,$crypt;
  214. $handle = func_getdb();
  215. $query = mysql_query("SELECT * FROM {$table} WHERE User = '{$_SESSION['user']}'" , $handle);
  216. $row = mysql_fetch_array( $query, MYSQL_ASSOC );
  217.     echo "<form name=\"userpassword\" id=\"userpassword\" method=\"post\" action=\"?action=userpasswordchang\">
  218. <table cellpadding=\"0\" cellspacing=\"0\" border=\"1\">
  219.     <tr>
  220.     <td colspan=\"2\" align=\"center\">服务器信息</td>
  221. </tr>
  222.     <tr>
  223.     <td width=\"100\" align=\"right\">ip</td><td width=\"500\">".gethostbyname($_SERVER['SERVER_NAME'])."</td>
  224. </tr>
  225. <tr>
  226.     <td colspan=\"2\" align=\"center\">账户信息</td>
  227. </tr>
  228. <tr>
  229.     <td width=\"100\" align=\"right\">用户名</td><td width=\"500\">".$row['User']."</td>
  230. </tr>
  231. <tr>
  232.     <td width=\"100\" align=\"right\">修改密码</td><td width=\"500\"><input type=\"password\" name=\"password\" id=\"password\" /> &nbsp; <input type=\"submit\" name=\"submit\" id=\"submit\" value=\"修改\" /></td>
  233. </tr>
  234. <tr>
  235.     <td width=\"100\" align=\"right\">Uid</td><td width=\"500\">".$row['Uid']."</td>
  236. </tr>
  237. <tr>
  238.     <td width=\"100\" align=\"right\">Gid</td><td width=\"500\">".$row['Gid']."</td>
  239. </tr>
  240. <tr>
  241.     <td width=\"100\" align=\"right\">Status</td><td width=\"500\">".$row['status']."</td>
  242. </tr>
  243. <tr>
  244.     <td width=\"100\" align=\"right\">Dir</td><td width=\"500\">".$row['Dir']."</td>
  245. </tr>
  246. <tr>
  247.     <td width=\"100\" align=\"right\">ULBandwidth</td><td width=\"500\">".$row['ULBandwidth']."</td>
  248. </tr>
  249. <tr>
  250.     <td width=\"100\" align=\"right\">DLBandwidth</td><td width=\"500\">".$row['DLBandwidth']."</td>
  251. </tr>
  252. <tr>
  253.     <td width=\"100\" align=\"right\">ipaccess</td><td width=\"500\">".$row['ipaccess']."</td>
  254. </tr>
  255. <tr>
  256.     <td width=\"100\" align=\"right\">QuotaSize</td><td width=\"500\">".$row['QuotaSize']."</td>
  257. </tr>
  258. <tr>
  259.     <td width=\"100\" align=\"right\">QuotaFiles</td><td width=\"500\">".$row['QuotaFiles']."</td>
  260. </tr>
  261. </table>
  262. </form>
  263. ";
  264. }
  265.  
  266. function user_password_chang( $password )
  267. {
  268.     global $crypt,$table;
  269.     if(empty($password))
  270. {
  271.     echo "密码不能为空,修改失败……";
  272. echo "</meta><meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=index\">";
  273. }
  274. else
  275. {
  276. $handle = func_getdb();
  277. $query = mysql_query("UPDATE {$table} SET Password = ".$crypt."('".$password."') WHERE User = '{$_SESSION['user']}'" , $handle);
  278. session_destroy();
  279. echo "修改成功,请重新登录。如果新的密码不能登录,请尝试使用旧密码进行登录……";
  280. echo "</meta><meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=userlogin\">";
  281. }
  282. }
  283.  
  284. function func_admin_index()
  285. {
  286.     global $table,$username,$password,$crypt;
  287. $handle = func_getdb();
  288. $query = mysql_query("SELECT * FROM {$table} ORDER BY User ASC" , $handle);
  289. echo "<script language=\"javascript\">
  290. function del( username )
  291. {
  292.     if(confirm('确认删除 '+username+'?'))
  293. {
  294.     window.location.href=\"?action=adminuserdel&user=\"+username;
  295. }
  296. else
  297. {
  298.     return false;
  299. }
  300. }
  301. </script><table cellpadding=\"0\" cellspacing=\"0\" border=\"1\">
  302. <tr>
  303. <td colspan=\"4\" align=\"center\">用户列表</td>
  304. <td align=\"right\"><input type=\"button\" name=\"add\" id=\"add\" value=\"添加账户\" onclick=\"window.location.href='?action=useradd'\" /></td>
  305. </tr>
  306. <tr>
  307. <td align=\"center\">账号</td>
  308. <td align=\"center\">Uid</td>
  309. <td align=\"center\">Gid</td>
  310. <td align=\"center\">Dir</td>
  311. <td align=\"center\">操作</td>   
  312. </tr>";
  313. while( $row = mysql_fetch_array( $query, MYSQL_ASSOC ) )
  314. {
  315.     echo "<tr>
  316. <td>".$row['User']."</td>
  317. <td align=\"center\">".$row['Uid']."</td>
  318. <td align=\"center\">".$row['Gid']."</td>
  319. <td>".$row['Dir']."</td>
  320. <td align=\"center\"><input type=\"button\" name=\"button\" id=\"button\" value=\"修改\" onclick=\"window.location.href='?action=adminchangeuserpassword&user=".$row['User']."'\" />
  321. <input type=\"button\" name=\"del\" id=\"del\" value=\"删除\" onclick=\"del('".$row['User']."')\" /></td>   
  322. </tr>";
  323. }
  324. echo "</table>";
  325. }
  326.  
  327. function func_admin_user_edit( $user = false )
  328. {
  329.     
  330.     if($user)
  331. {
  332.     global $table,$crypt;
  333. $handle = func_getdb();
  334. $query = mysql_query("SELECT * FROM {$table} WHERE User = '".$user."'" , $handle);
  335. $row = mysql_fetch_array( $query, MYSQL_ASSOC );
  336. if($row==false)
  337. {
  338.     echo "不存在这个用户……";
  339.     echo "</meta><meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=index\">";
  340. exit();
  341. }
  342. $action = "edit";
  343. }
  344. else
  345. {
  346.     $row["User"] = "";
  347. $row['Uid'] = "";
  348. $row['Gid'] = "";
  349. $row['status'] = 0;
  350. $row['Dir'] = "";
  351. $row['ULBandwidth'] = 0;
  352. $row['DLBandwidth'] = 0;
  353. $row['ipaccess'] = "*";
  354. $row['QuotaSize'] = 0;
  355. $row['QuotaFiles'] = 0;
  356. $action = "add";
  357. }
  358. echo "<form name=\"userpassword\" id=\"userpassword\" method=\"post\" action=\"?action=userinfoac\">
  359. <table cellpadding=\"0\" cellspacing=\"0\" border=\"1\">
  360. <tr>
  361.     <td colspan=\"2\" align=\"center\">账户信息</td>
  362. </tr>
  363. <tr>
  364.     <td width=\"100\" align=\"right\">用户名</td><td width=\"500\">";
  365. if($action=="add")
  366. {
  367.     echo  "<input type=\"text\" name=\"User\" id=\"User\" value=\"".$row['User']."\" />";
  368. }
  369. else
  370. {
  371.     echo  $row['User']."<input type=\"hidden\" name=\"User\" id=\"User\" value=\"".$row['User']."\" />";
  372. }
  373. echo "</td>
  374. </tr>
  375. <tr>
  376.     <td width=\"100\" align=\"right\">密码</td><td width=\"500\"><input type=\"password\" name=\"password\" id=\"password\" /> </td>
  377. </tr>
  378. <tr>
  379.     <td width=\"100\" align=\"right\">Uid</td><td width=\"500\"> <input type=\"text\" name=\"Uid\" id=\"Uid\" value=\"".$row['Uid']."\" /></td>
  380. </tr>
  381. <tr>
  382.     <td width=\"100\" align=\"right\">Gid</td><td width=\"500\"> <input type=\"text\" name=\"Gid\" id=\"Gid\" value=\"".$row['Gid']."\" /></td>
  383. </tr>
  384. <tr>
  385.     <td width=\"100\" align=\"right\">Status</td><td width=\"500\"> <input type=\"text\" name=\"status\" id=\"status\" value=\"".$row['status']."\" /></td>
  386. </tr>
  387. <tr>
  388.     <td width=\"100\" align=\"right\">Dir</td><td width=\"500\"> <input type=\"text\" name=\"Dir\" id=\"Dir\" value=\"".$row['Dir']."\" /></td>
  389. </tr>
  390. <tr>
  391.     <td width=\"100\" align=\"right\">ULBandwidth</td><td width=\"500\"> <input type=\"text\" name=\"ULBandwidth\" id=\"ULBandwidth\" value=\"".$row['ULBandwidth']."\" /></td>
  392. </tr>
  393. <tr>
  394.     <td width=\"100\" align=\"right\">DLBandwidth</td><td width=\"500\"> <input type=\"text\" name=\"DLBandwidth\" id=\"DLBandwidth\" value=\"".$row['DLBandwidth']."\" /></td>
  395. </tr>
  396. <tr>
  397.     <td width=\"100\" align=\"right\">ipaccess</td><td width=\"500\"> <input type=\"text\" name=\"ipaccess\" id=\"ipaccess\" value=\"".$row['ipaccess']."\" /></td>
  398. </tr>
  399. <tr>
  400.     <td width=\"100\" align=\"right\">QuotaSize</td><td width=\"500\"> <input type=\"text\" name=\"QuotaSize\" id=\"QuotaSize\" value=\"".$row['QuotaSize']."\" /></td>
  401. </tr>
  402. <tr>
  403.     <td width=\"100\" align=\"right\">QuotaFiles</td><td width=\"500\"> <input type=\"text\" name=\"QuotaFiles\" id=\"QuotaFiles\" value=\"".$row['QuotaFiles']."\" /></td>
  404. </tr>
  405. <tr>
  406.     <td align=\"center\" colspan=\"2\"><input type=\"submit\" name=\"submit\" id=\"submit\" value=\"提交\" /> <input type=\"button\" name=\"back\" id=\"back\" onclick=\"window.history.go(-1)\" value=\"返回\" /> <input type=\"hidden\" name=\"action\" id=\"action\" value=\"".$action."\" /></td>
  407. </tr>
  408. </table>
  409. </form>";
  410. }
  411.  
  412. function func_admin_useredit()
  413. {
  414.     global $table,$crypt;
  415. $handle = func_getdb();
  416. $query = mysql_query("SELECT * FROM {$table} WHERE User = '".$_POST['User']."'" , $handle);
  417. $row = mysql_fetch_array( $query, MYSQL_ASSOC );
  418. if($row==false)
  419. {
  420. echo "不存在这个用户……";
  421. echo "</meta><meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=index\">";
  422. exit();
  423. }
  424. $query = mysql_query("UPDATE {$table} SET password = ".$crypt."('".$_POST['password']."') , Uid = {$_POST['Uid']} , Gid = {$_POST['Gid']} , status = '{$_POST['status']}' , Dir = '{$_POST['Dir']}' , ULBandwidth = {$_POST['ULBandwidth']} , DLBandwidth = {$_POST['DLBandwidth']} , ipaccess = '{$_POST['ipaccess']}' , QuotaSize = {$_POST['QuotaSize']} , QuotaFiles = {$_POST['QuotaFiles']} WHERE User = '{$_POST['User']}'");
  425. if($query)
  426. {
  427.     echo "修改成功,稍后返回……";
  428. }
  429. else
  430. {
  431.     echo "修改失败,请仔细检查每个参数……";
  432. }
  433. echo "</meta><meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=index\">";
  434. exit();
  435. }
  436.  
  437. function func_admin_useradd()
  438. {
  439.     global $table,$crypt;
  440. $handle = func_getdb();
  441. $query = mysql_query("SELECT * FROM {$table} WHERE User = '".$_POST['User']."'" , $handle);
  442. $row = mysql_fetch_array( $query, MYSQL_ASSOC );
  443. if($row)
  444. {
  445. echo "用户已经存在……";
  446. echo "</meta><meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=index\">";
  447. exit();
  448. }
  449. $query = mysql_query("INSERT INTO {$table} SET password = ".$crypt."('".$_POST['password']."') , Uid = {$_POST['Uid']} , Gid = {$_POST['Gid']} , status = '{$_POST['status']}' , Dir = '{$_POST['Dir']}' , ULBandwidth = {$_POST['ULBandwidth']} , DLBandwidth = {$_POST['DLBandwidth']} , ipaccess = '{$_POST['ipaccess']}' , QuotaSize = {$_POST['QuotaSize']} , QuotaFiles = {$_POST['QuotaFiles']} , User = '{$_POST['User']}' , comment = ''");
  450. if($query)
  451. {
  452.     echo "添加成功,稍后返回……";
  453. }
  454. else
  455. {
  456.     echo "添加失败,请仔细检查每个参数……";
  457. }
  458. echo "</meta><meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=index\">";
  459. exit();
  460. }
  461.  
  462. function func_user_del( $user )
  463. {
  464.     global $table;
  465. $handle = func_getdb();
  466. $query = mysql_query("DELETE FROM {$table} WHERE User = '{$user}'" , $handle);
  467. if($query)
  468. {
  469.     echo "删除成功,稍后返回……";
  470. }
  471. else
  472. {
  473.     echo "删除失败,稍后返回……";
  474. }
  475. echo "</meta><meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=index\">";
  476. }
  477.  
  478. function func_logout()
  479. {
  480.     session_destroy();
  481. echo "退出成功……";
  482. echo "</meta><meta http-equiv=\"Refresh\" content=\"1; url=".FILENAME."?action=userlogin\">";
  483. }
  484. ?>
  485. </meta>

RSS解析类-SimplePie

作者 : admin 于 2009年07月08日, 09:31:05
2009
07-8

最近做一个RSS解析调用的东东,研究了rss2.0的协议,发现自己去写解析程序会要命的,于是找了个开源的php rss解析类,发现完全可以满足需求,故推荐给大家。虽然有一些bug,但是可以绕过,不影响主要字段显示,先这么用着。底下写了个demo:

  1. $this->load("SimplePie","http://www.sunboyu.cn/feed");   #自己写的框架,load是加载类的方法,可根据自己的情况进行修改 new Simplepie()
  2. $this->SimplePie->strip_comments(true);
  3. $this->SimplePie->enable_xml_dump( false );
  4. $this->SimplePie->init();
  5. $this->SimplePie->handle_content_type();
  6.  
  7. foreach( $r as $item ):
  8.     echo "<font color=\"red\">标题</font>  ".$item->get_title();
  9.     echo "<br />";
  10.     echo "<font color=\"red\">链接</font>  ".$item->get_link();
  11.     echo "<br />";
  12.     echo "<font color=\"red\">链接</font>  ".$item->get_id();
  13.     echo "<br />";
  14.     echo "<font color=\"red\">更新时间</font>  ".strtotime($item->get_date());
  15.     echo "<br />";
  16.     $authors = $item->get_authors();
  17.     echo "<font color=\"red\">作者</font>  ".$authors[0]->name;
  18.     echo "<br />";
  19.     echo "<font color=\"red\">描述</font>  ".$item->get_description();
  20.     echo "<br />";
  21.     echo $item->get_local_date();
  22.     echo "<br />";
  23.     echo "<font color=\"red\">正文</font>  ".$item->get_content();
  24.     echo "<br /><br />";
  25. foreachend;

在windows下玩apache php不能不知的几个小设置

作者 : admin 于 2009年06月10日, 17:09:26
2009
06-10

1、PHPIniDir “D:\PHP5″

这样不用每次都把php.ini拷贝到C:\Windows下

2、set Path=D:\PHP5;D:\PHP5\ext;%Path%

这样不用每次把那些dll拷贝到C:\Windows\system32下

 Page 3 of 10 « 1  2  3  4  5 » ...  Last »