Archive for the ‘PHP’ Category

用KSES过滤指定html标签

星期三, 04月 2nd, 2008

无论是ASP、还是PHP,有很多的editor都转用html编辑器,放弃了传统的UBB编辑器,如果是自己或自己信的过的人提交带有HTML代码,可能这不会出现什么问题,但是如果给别有用心的人利用了,可能会有很大的隐患,但是全部屏蔽了HTML,那又不会显示我们想要的效果。

于是KSES出现了,KSES就是过滤全部除程序员指定的HTML TAG以外的一个函数,同时KSES是开源的。
KSES的官方网站地址是:http://sourceforge.net/projects/kses 你可以在这下载最新的kses

下载好,取出来根目录的里的 kses.php,然后我们动手做一个测试:

<?
include ‘kses.php’;//定义一个用来测试的带有HTML TAG的字符串
$string = ‘<strong>test STRONG tag</strong>,<b>test B tag</b>’;//允许的html tag 数组
$kses_allowed = array (’strong’ => array ());

//输出过滤后的结果
echo kses($string, $kses_allowed);
?> 

 

 

PHP运行在Windows Server 2008下:性能提高130%

星期二, 04月 1st, 2008

我们知道Windows Server 2008 IIS内置的FastCGI机制可以让PHP的解析速度大幅提高,但详细数据是多少呢?MSDN上的告诉我们,一倍还多,130%!
该数据来自新加坡网站StreetDirectory.com,他们部署Windows Server 2008当Web服务器后得到了明显的性能提升,如图:

据网站方面称从用户回馈来看,PHP程序的运行甚至比原生的LAMP环境还要好,他们没有针对访问进行任何优化,所有工作仅仅是升级到Windows Server 2008而已.

这样,网站放就可以以相同的投入获得更高的支撑能力,节省了成本.

警惕php setcookie作用域里的规范

星期六, 03月 22nd, 2008

这里写的很清楚,cn域名没在内

Only hosts within the specified domain can set a cookie for a domain and domains must have at least two (2) or three (3) periods in them to prevent domains of the form: “.com”, “.edu”, and “va.us”. Any domain that fails within one of the seven special top level domains listed below only require two periods. Any other domain requires at least three. The seven special top level domains are: “COM”, “EDU”, “NET”, “ORG”, “GOV”, “MIL”, and “INT”.

详细文档:http://wp.netscape.com/newsref/std/cookie_spec.html

解决办法:用javascript写cookie

PHP Class 变量封装生成器

星期六, 03月 15th, 2008

不记得去年什么时候写的,最近用到,发现还能用,没什么技术含量的javascript代码
http://liuyami.com/labs/setget.html