手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表Tag:mysql

jQuery的html()等方法介绍

本来是看到一篇文章,写研究的,想COPY过来就完事了。该来来自于cssRain,但是在看的过程中,发现内容和标准偏差很多,于是就贴上它的链接,然后自己谈谈理解吧。

CSSRAIN的链接为:http://www.cssrain.cn/article.asp?id=1176

在jQuery里面对于一些HTML的元素操作都是很简化的,这也是很多人选择使用jQuery的原因。

对于获取某一个元素的值,如input框,我们往往是用$('#test').val();

$('#test')这个我就不多说了,反正就是获取ID为test的这个元素。

$('#test').val(),也就是获取它的值,一般来说,凡是能够用在FORM里的元素,都可以用.val()来进行值的获取,如input,textarea,select等,都可以用.val()来获取它们的当前值

而.val('aa');则是设置该元素的值,$('#test').val('aa'),也就是相当于设置test元素的值为aa。

类似这样的用法还有两种:.html(),.text(),这两种用法往往用在div和span元素上,一般是为这两种元素进行赋值和取值。

.html()替代了以前的 .innerHTML , .html('test') ,则是替代了 .innerHTML = 'test';

这些类似的简化写法让我们在实际的操作中感觉得更加流畅。

这些方法都是直接在方法名里加参数来进行赋值和取值的。还有一些是通过第二个参数进行取值的(说的不太清楚。。。),比如$('#test').attr('name'),那么,返回的值就是它的attribute中的name了,如果$('#test').attr('id','test2'),则是相当于把这个test元素的name设为test2,再进行取值的时候,name就是test2了。

说的太乱了。。。。

懒得整理,权当笔记

Tags: jquery, html, 研究

PDF下载:《High Performance MySQL》

回忆未来的张宴推荐了这本书,并且在他的博客上提供了下载的链接,链接是新浪的爱问:点此下载《High Performance MySQL Second Edition》PDF电子版,并且博客上还有详细介绍:

  XML/HTML代码

  1. High Performance MySQL Second Edition  
  2. 作者: Baron Schwartz / Peter Zaitsev / Vadim Tkachenko / Jeremy Zawodny / Arjen Lentz / Derek Balling  
  3.   
  4. 副标题: Optimization, Backups, Replication, and More  
  5. ISBN: 9780596101718  
  6. 页数: 708  
  7. 定价: USD 49.99  
  8. 出版社: O'Reilly Media, Inc.  
  9. 装帧: Paperback  
  10. 出版年: 2008-06-18  
  11.   
  12. High Performance MySQL is the definitive guide to building fast, reliable systems with MySQL. Written by noted experts with years of real-world experience building very large systems, this book covers every aspect of MySQL performance in detail, and focuses on robustness, security, and data integrity.  
  13.   
  14. High Performance MySQL teaches you advanced techniques in depth so you can bring out MySQL's full power. Learn how to design schemas, indexes, queries and advanced MySQL features for maximum performance, and get detailed guidance for tuning your MySQL server, operating system, and hardware to their fullest potential. You'll also learn practical, safe, high-performance ways to scale your applications with replication, load balancing, high availability, and failover.  
  15.   
  16. This second edition is completely revised and greatly expanded, with deeper coverage in all areas. Major additions include:  
  17. * Emphasis throughout on both performance and reliability  
  18. * Thorough coverage of storage engines, including in-depth tuning and optimizations for the InnoDB storage engine  
  19. * Effects of new features in MySQL 5.0 and 5.1, including stored procedures, partitioned databases, triggers, and views  
  20. * A detailed discussion on how to build very large, highly scalable systems with MySQL  
  21. * New options for backups and replication  
  22. * Optimization of advanced querying features, such as full-text searches  
  23. * Four new appendices  
  24. The book also includes chapters on benchmarking, profiling, backups, security, and tools and techniques to help you measure, monitor, and manage your MySQL installations.  

为此,张宴还提供了一张图片:

 

大小: 5.18 K
尺寸: 106 x 139
浏览: 2108 次
点击打开新窗口浏览全图

 

整篇博客我作了一下整理和排序,想看原文的,请到:http://blog.s135.com/read.php?381,因为在这个页面上张宴采用了划词翻译,如果有看不懂英文的话,选中一下就会自动翻译了。。我没有提供。也不想再插入一些代码。呵呵

为了方便大家,我也上传了这个文件,大家可以点击下载:high.performance.mysql_second.edition.zip


Tags: mysql, database, pdf, download

不要轻信 PHP_SELF

原文地址:http://www.phpv.net/html/1639.html,作者:手气不错

未删节版本

开门见山,考虑下面的代码(原文连接有详细的解释)

PHP代码
  1. <html>  
  2.     <body>  
  3.         <?php  
  4.             if (isset($_REQUEST['submitted']) && $_REQUEST['submitted'] == '1') {  
  5.                 echo "Form submitted!";  
  6.             }  
  7.         ?>  
  8.         <form action="<?php echo $_SERVER['PHP_SELF']; ?>">  
  9.             <input type="hidden" name="submitted" value="1" />  
  10.             <input type="submit" value="Submit!" />  
  11.         </form>  
  12.     </body>  
  13. </html>  

看似准确无误的代码,但是暗藏着危险。让我们将其保存为 foo.php ,然后放到 PHP 环境中使用

foo.php/%22%3E%3Cscript%3Ealert('xss')%3C/script%3E%3Cfoo

访问,会发现弹出个 Javascript 的 alert -- 这很明显又是个 XSS 的注入漏洞。究其原因,发现是在

echo $_SERVER['PHP_SELF'];

这条语句上直接输出了未过滤的值。追根数源,我们看下 PHP 手册的描述

'PHP_SELF'

The filename of the currently executing script, relative to the document root.
For instance, $_SERVER['PHP_SELF'] in a script at the address
http://example.com/test.php/foo.bar would be /test.php/foo.bar. The __FILE__
constant contains the full path and filename of the current (i.e. included) file.
If PHP is running as a command-line processor this variable contains the script
name since PHP 4.3.0. Previously it was not available.

原因很明确了,原来是 $_SERVER['PHP_SELF'] 虽然“看起来”是服务器提供的环境变量,但这的确和 $_POST 与 $_GET 一样,是可以被用户更改的。

其它类似的变量有很多,比如 $_COOKIE 等(如果用户想“把玩”他们的 cookie,那我们也是没有办法)。解决方案很简单,使用 strip_tagshtmlentities 等此类函数过滤或者转义。

echo htmlentities($_SERVER['PHP_SELF']);

-- Split --

上述的例子让我们需要时刻保持谨慎 coding 的心态。Chris Shiflett 在他的 Blog 总结的相当直白,防止 XSS 的两个基本的安全思想就是

Filter input
Escape output

我将上面翻译成 “过滤输入,转义输出”。详细的内容,可以参考他 Blog 的这篇文章,此处略。

Tags: php, php_self

支付宝已支持 Linux 下的 Firefox

小道消息:Linux 操作系统下的 Firefox 用户,从现在开始也可以用支付宝了。参见支付宝官方网志安装指导。最近微软黑屏事件闹得挺凶,但这个时候支付宝发布新的安全控件,应该和此事无关。

至于很多苹果用户期待的在 Mac 下使用支付宝的事情,请稍安勿躁,有望在 11 月中旬得到解决。届时也将在支付志第一时间发布。支付宝安全工程师一直在努力!

支持 Mac 操作系统,通用的数字证书,更为安全、开放的支付宝时代即将到来。

原文:http://www.dbanotes.net/opensource/alipay_linux_firefox.html

Tags: 支付宝, linux, firefox, alipay, mac

两年前写的php之call_user_func_array的简易用法

几年前写的东西了,翻出来重贴一下,呵呵


今天在群里面,有个叫lewis的在问call_user_func_array的用法,因为之前一直没有用过,也不能说什么,于是看一下手册,发现是这么写的:

call_user_func_array

(PHP 4 >= 4.0.4, PHP 5)

call_user_func_array --  Call a user function given with an array of parameters

Description

mixed call_user_func_array ( callback function, array param_arr )

Call a user defined function given by function, with the parameters in param_arr.
然后还有一个例子:

PHP代码
  1. <?php  
  2. function debug($var$val)   
  3. {  
  4.     echo "***DEBUGGING\nVARIABLE: $var\nVALUE:";  
  5.     if (is_array($val) || is_object($val) || is_resource($val)) {  
  6.         print_r($val);  
  7.     } else {  
  8.         echo "\n$val\n";  
  9.     }  
  10.     echo "***\n";  
  11. }  
  12.   
  13. $c = mysql_connect();  
  14. $host = $_SERVER["SERVER_NAME"];  
  15.   
  16. call_user_func_array('debug'array("host"$host));  
  17. call_user_func_array('debug'array("c"$c));  
  18. call_user_func_array('debug'array("_POST"$_POST));  
  19. ?>   
相信看了例子之后应该有点明白了吧?
我自己是这么理解这个函数的,如果说的不对,还望各位高手不要耻笑:
     该函数真正的用法有点类似于函数重载,因为他的第一个参数是字符型的,也就是函数的名称,第二个参数是数组,我们可以当成该函数的各个参数,而事实上也就是这么用的,如果你看过我的前一篇文章:PHP的伪重载 ,或许你能够理解,正是因为这个函数的存在,我发现函数重载也可以这样运用:

PHP代码
  1. <?php  
  2. /** 
  3. * 例子写完后,本来认为完事了,结果遇到有人问call_user_func_array(),看了一下手册 
  4. * 原来,我上面的那个test函数还可以精简成如下的例子, 
  5. */  
  6. function otest1 ($a)  
  7. {  
  8.     echo'一个参数' );  
  9. }  
  10.   
  11. function otest2 ( $a$b)  
  12. {  
  13.     echo'二个参数' );  
  14. }  
  15.   
  16. function otest3 ( $a ,$b,$c)  
  17. {  
  18.     echo'三个啦' );  
  19. }  
  20.   
  21. function otest ()  
  22. {  
  23.     $args = func_get_args();  
  24.     $num = func_num_args();  
  25.     call_user_func_array( 'otest'.$num$args  );  
  26. }  
  27.   
  28. otest(1,2);  
看到不?而我最初的写法,在PHP的伪重载一文中有所提及,仅作参考。。。。

这些只是call_user_func_array的简易用法,在PHP4下测试过,而手册中还有一些将第一个参数当成数组来传入的例子,我在PHP4下是没有办法运行的,也许PHP5可以吧,但我不用PHP5的,也没有办法解释什么。谢谢各位


以前一直用PHP4的,现在用PHP5了,关于这个函数,大家可以看看thinkphp的functions.php中的getInstance方法,也是一个很好的诠释哦。

 

Tags: 自定义, php, 伪重载, 多态