<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jeff&#039;s Blog &#187; 程序开发</title>
	<atom:link href="http://www.jefflei.com/category/web-development/feed" rel="self" type="application/rss+xml" />
	<link>http://www.jefflei.com</link>
	<description></description>
	<lastBuildDate>Thu, 28 Oct 2010 04:44:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>ZF1.8 DB字符集设定</title>
		<link>http://www.jefflei.com/post/1639.html</link>
		<comments>http://www.jefflei.com/post/1639.html#comments</comments>
		<pubDate>Mon, 10 Aug 2009 16:41:54 +0000</pubDate>
		<dc:creator>inetdemon</dc:creator>
				<category><![CDATA[程序开发]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.jefflei.com/?p=1639</guid>
		<description><![CDATA[Zend Framework的db 字符集设置，由于ZF的一个bug，以前在设置db的字符集为utf-8时，通常是在bootstrap中设定 $db = Zend_Db::factory($this-&#62;_config-&#62;db); $db-&#62;query("SET NAMES utf8");  //setup encoding 这种做法的一个缺点就是DB的lazy loading机制变得无效，所有不调用数据库的页面也需要去打开一个数据库链接。困难之处在于每种数据库的charset名称并不相同，之前一直有一个提议，将charset做一个db的option来设置，ZF1.7开始将这个建议实施，现在我们可以用如下方法，设置db的option &#60;?php $db = new Zend_Db_Adapter_Pdo_Mysql(array( 'host'     =&#62; 'your_host_or_ip', 'username' =&#62; 'your_myslq_username0, 'password' =&#62; 'mysql_pass', 'dbname'   =&#62; 'your_db_name', 'driver_options'  =&#62; array(PDO::MYSQL_ATTR_INIT_COMMAND =&#62; 'SET NAMES \'utf8\'') ));?&#62; 除此之外，还可以在config中设置，不过由于config文件并不认得常量，因此只能用以下方式来设置： db.params.driver_options.1002 = “SET NAMES utf8&#8243; 其中1002即PDO::MYSQL_ATTR_INIT_COMMAND这个常量的值。 如果想直接修改DB的charset collocation可以参考mysql的charset转化指南。 感谢 julian的提醒，自从ZF1.8开始已经可以使用db.param.charset=”UTF-8&#8243;来设定; 如果使用的是Zend_Application,可以设定resource.db.params.charset=”UTF-8&#8243;.]]></description>
		<wfw:commentRss>http://www.jefflei.com/post/1639.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Zend Framework 1.8 中的Model</title>
		<link>http://www.jefflei.com/post/1534.html</link>
		<comments>http://www.jefflei.com/post/1534.html#comments</comments>
		<pubDate>Fri, 31 Jul 2009 23:36:19 +0000</pubDate>
		<dc:creator>inetdemon</dc:creator>
				<category><![CDATA[程序开发]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.jefflei.com/?p=1534</guid>
		<description><![CDATA[在ZF1.8以后Module的问题得以完善，但是仍然有很多领域需要改进，Model就是其中一个 Model的类型用DbTable&#60;-&#62;Mapper&#60;-&#62;Model的DataMapper Pattern (同时参照IdentityMap和UnitOfWork)来调用，其中对象Model用于导入对象，导入后就由UOW拥有的Identity对象来跟踪，以此来保持数据的同步。比如一个Users表，我们有如下类: Model_User是业务域模型(domain Model)，关于domain design的模式可以参见domain driven design一书。 Model_UserMapper来完成Model对象和数据库的映射关系 Model_DbTable_Users extends Zend_Db_Table_Abstract类负责数据库方面的设定 以上pattern的使用在这篇帖子和Zend 的proposal中有讨论到。这个Pattern的好处是，如果你将来不用数据库来保存数据，而换用文件或者Memcached，那么你就不用修改你的Controller了；从来引来的一个缺点是几乎每个调用都需要来定义Mapper，从而导致复杂度提高。通常情况下对于不是比较复杂的情况，1:1的应用来说，Table Gatewy, Row, Rowset的Pattern已经足够使用。 关于DataMapper的Model使用模型还在更新过程中，同时还有个datashuffler在ZF上的实现目前也在研究中。]]></description>
		<wfw:commentRss>http://www.jefflei.com/post/1534.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ZF1.8 快速上手</title>
		<link>http://www.jefflei.com/post/1505.html</link>
		<comments>http://www.jefflei.com/post/1505.html#comments</comments>
		<pubDate>Wed, 29 Jul 2009 22:03:09 +0000</pubDate>
		<dc:creator>inetdemon</dc:creator>
				<category><![CDATA[程序开发]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.jefflei.com/?p=1505</guid>
		<description><![CDATA[ZF有段时间没有弄了，自从ZF1.8出来之后改动比较大，把一些东西整理一下，温故而知新。 首先是下载ZendFramework，由于ZF的版本更新很快，一些小版本基本是2周出一次，下载最新的ZF，下载后将ZF放到系统类库目录，我们假设是/usr/local/lib/, 其次，将ZF添加到系统目录中去，可以修改php.ini(如果不确定php.ini所在目录，可以通过phpinfo查看），在include_path中增加如下目录：include_path=”.:/path/to/zf:/usr/share/php:/usr/share/pear”，对于以ZF为主的系统，将ZF包含目录放在最前面有助提高效率，详细请看这篇文章。在进行下一步之前，我们需要先确定目录构造，请参见ZF所推荐的Zend Framework的目录结构。 开始工作，首先index.php比较简单： &#60;?php // Define path to application directory defined('APPLICATION_PATH') &#124;&#124; define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application')); // Define application environment defined('APPLICATION_ENV') &#124;&#124; define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production')); // Ensure library/ is on include_path set_include_path(implode(PATH_SEPARATOR, array( realpath(APPLICATION_PATH . '/../library'), get_include_path(), ))); /** Zend_Application */ require_once 'Zend/Application.php';   // Create application, bootstrap, and run [...]]]></description>
		<wfw:commentRss>http://www.jefflei.com/post/1505.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XSS攻击防范</title>
		<link>http://www.jefflei.com/post/1239.html</link>
		<comments>http://www.jefflei.com/post/1239.html#comments</comments>
		<pubDate>Wed, 22 Apr 2009 16:28:07 +0000</pubDate>
		<dc:creator>inetdemon</dc:creator>
				<category><![CDATA[程序开发]]></category>
		<category><![CDATA[互联网安全]]></category>

		<guid isPermaLink="false">http://www.jefflei.com/?p=1239</guid>
		<description><![CDATA[最近一个朋友找我帮忙修复一个XSS注入漏洞，其实网站也是某上市互联网公司的中国站。现在XSS和CSRF攻击成为一个WEB软件工作者不得不重视的一个问题，很有必要深入研究下。 XSS漏洞很容易在大型网站中发现，在黑客圈内它非常流行。最著名的是2005年黑客Sammy Kamkar在myspace网站发布蠕虫病毒后，XSS就开始大行其道。FBI.gov、CNN.com、Time.com、Ebay、 Yahoo、Apple、Microsoft、Zdnet、Wired、Newsbytes，twitter都有这样那样的XSS漏洞。国内出现过XSS漏洞的网站有sohu，网易邮箱，校内网等，百度和著名电商网站淘宝也曾出现过XSS漏洞。 在商业产品中，平均每个月能够发现10-25个XSS漏洞。 假设你已经了解XSS的基本概念和类型，这里看看如何进行防范。先总结一下常见的XSS攻击手法： 依赖跨站漏洞，需要在被攻击网站的页面种入XSS脚本的手法 Cookie 盗取，通过javascript 获取被攻击网站种下的cookie，并发送给攻击者。 1.从cookie 中提取密码等隐私 2. 利用cookie 伪造session，发起重放攻击 Ajex 信息盗取，通过javascript 发起ajex 请求。 1. 从ajex 结果中获取隐私。 2. 模拟用户完成多页表单。 不依赖跨站漏洞的XSS攻击手法 1. 单向HTTP 动作，通过img.src 等方法发起跨站访问，冒充被攻击者执行特权操作。但是很难拿到服务器的返回值。 2. 双向HTTP 动作，如果服务器产生一段动态的script，那么可以用script.src 的方法发起跨站访问并拿到服务器的返回值。 XSS防范方法 XSS攻击防范主要是有程序漏洞造成的，要完全防止XSS安全漏洞主要依靠程序员较高的编程能力和安全意识，当然一些编程安全原则可以帮助大大减少XSS安全漏洞： 不信任用户提交的任何内容，对所有用户提交内容进行可靠的输入验证，包括对URL、查询关键字、HTTP头、REFER、POST数据等，仅接受指定长度范围内、采用适当格式、采用所预期的字符的内容提交，对其他的一律过滤。尽量采用POST 而非GET 提交表单；对”&#60;”,”&#62;”,”;”,”’”等字符做过滤；任何内容输出到页面之前都必须加以encode，避免不小心把html tag 弄出来。 实现Session标记(session tokens)、CAPTCHA系统或者HTTP引用头检查，以防功能被第三方网站所执行，对于用户提交信息的中的img 等link，检查是否有重定向回本站、不是真的图片等可疑操作。 Cookie 防盗。避免直接在cookie 中泄露用户隐私，例如email、密码等等；通过使cookie 和系统ip 绑定来降低cookie 泄露后的危险。这样攻击者得到的cookie 没有实际价值，不可能拿来重放。 确认接收的的内容被妥善的规范化，仅包含最小的、安全的Tag(没有javascript)，去掉任何对远程内容的引用(尤其是样式表和javascript)，使用HTTP only的cookie。 PHP方面请参见PHP的安全防范工作 ASP.Net的可以用VS自带的XSSDetect来检测。 要更好的防范XSS和CSRF攻击等，除了加强程序开发的严谨度之外，还需要重视测试工作，通过专业的测试来减少问题发生的可能性，我们看到淘宝QA也重视XSS攻击测试了。]]></description>
		<wfw:commentRss>http://www.jefflei.com/post/1239.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>用php控制你的MSN消息</title>
		<link>http://www.jefflei.com/post/503.html</link>
		<comments>http://www.jefflei.com/post/503.html#comments</comments>
		<pubDate>Wed, 21 Jan 2009 14:58:57 +0000</pubDate>
		<dc:creator>inetdemon</dc:creator>
				<category><![CDATA[程序开发]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://localhost/wp/?p=503</guid>
		<description><![CDATA[从Facebook到开心网，很多SNS应用都使用了msn服务，关于MSN的协议的详细信息可以看半官方网站MSNPiki。使用MSN的php类也不少，这里介绍两个，第一个是PHP MSN Class，这个类比较简单，可以用来发送MSN消息，支持MSNP9 (MSN 6.2)和最新的MSNP15 (WLM 8.1)协议（MSNP15协议支持离线消息），可以作为MSN机器人使用，或者给MSN、雅虎通发消息。 &#60;?php include_once(&#8216;msn.class.php&#8217;); $msn_username = “username@hotmail.com”;//发送者MSN帐号 $msn_password = “12341234&#8243;;//发送者MSN密码 $msn_list = array(“user1@hotmail.com”,”user2@live.cn”);//消息接收者MSN帐号 $msn = new MSN(&#8216;MSNP15&#8242;);//采用MSNP15协议，支持离线消息 if ($msn-&#62;connect($msn_username, $msn_password)) {     $msn-&#62;sendMessage(“UTF-8编码的中文和英文”, $msn_list); } ?&#62; 使用MSNP15协议，PHP需要支持mhash；使用msnbot机器人功能，PHP需要支持pcntl。 phpMSN：基于PHP的MSN Messenger客户端连接接口。 MSN Messenger Class：这是一个支持MSNP协议的简单易用的PHP类库，它通过php_curl模块来实现对SSL的支持，目前，支持MSN9协议。 Blobsy：一个基于PHP开发的开源MSN Messager机器人。它设计灵活易用，便于安装，而且可定制，功能强大，内建模块包括让MSN上google帮你查资料等，这篇中文博客有不少介绍。 Naneau MSN：另一个用ZF开发的MSN类， 包括消息发送，获取联系人清单等。 Contact Grabber: 可以抓取MSN，GMAIL，Yahoo Messenger等联系人信息。 这里还有些介绍付费的contact抓取类，还支持aol，icq等：http://script.wareseeker.com/free-contact-importer-address-book-grabber-for-hotmail-gmail-yahoo-msn-aol/]]></description>
		<wfw:commentRss>http://www.jefflei.com/post/503.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP下处理Excel文件总结</title>
		<link>http://www.jefflei.com/post/412.html</link>
		<comments>http://www.jefflei.com/post/412.html#comments</comments>
		<pubDate>Tue, 13 Jan 2009 17:04:15 +0000</pubDate>
		<dc:creator>inetdemon</dc:creator>
				<category><![CDATA[程序开发]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://localhost/wp/?p=412</guid>
		<description><![CDATA[参照这篇总结，貌似php excel比较好：http://xinsync.xju.edu.cn/index.php/archives/3858]]></description>
		<wfw:commentRss>http://www.jefflei.com/post/412.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>EAV表建模探索</title>
		<link>http://www.jefflei.com/post/159.html</link>
		<comments>http://www.jefflei.com/post/159.html#comments</comments>
		<pubDate>Thu, 11 Dec 2008 10:25:42 +0000</pubDate>
		<dc:creator>inetdemon</dc:creator>
				<category><![CDATA[程序开发]]></category>

		<guid isPermaLink="false">http://localhost/wp/?p=159</guid>
		<description><![CDATA[EAV模型代表Entity-Attribute-Value,最早用于医学用途，医生在就诊时需要记录很多病人的参数，如体温，年龄，过敏药等情况，而这些参数并不是每个病人都需要记录的。 由于商品的多样性，用EAV表来描述商品的各种属性也很合适。老牌电子商务应用oscommerce的表设计(为了简洁，我将商品属性名和属性值的关系表略去)：             -- 商品表 CREATE TABLE `products` ( `id` int(11) NOT NULL auto_increment, `products_name` varchar(50) default NULL, PRIMARY KEY (`id`) ); -- 商品属性表           CREATE TABLE `products_attributes` ( `id` int(11) NOT NULL auto_increment, `products_id` int(11) NOT NULL default '0', `attribute_name` varchar(50) default NULL, PRIMARY KEY [...]]]></description>
		<wfw:commentRss>http://www.jefflei.com/post/159.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Zend Session使用要点</title>
		<link>http://www.jefflei.com/post/113.html</link>
		<comments>http://www.jefflei.com/post/113.html#comments</comments>
		<pubDate>Thu, 16 Oct 2008 06:29:26 +0000</pubDate>
		<dc:creator>inetdemon</dc:creator>
				<category><![CDATA[程序开发]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://localhost/wp/?p=113</guid>
		<description><![CDATA[在Zend_Session使用中需要注意以下几点 1. 关闭PHP的 session.auto_start setting. 在php.ini, 或者 .htaccess中写： php_value session.auto_start 0 2.不要直接使用session_start() 和Zend_Session_Namespace有冲突。 3.简单方法：可以直接new一个Zend_Session_Namespace，但是这种方法需要注意不要在此代码之前输出header. 4.麻烦但是不容易出问题的方法：使用Zend_Session::setOptions() 设置为strict, 防止自动自动zend session；在bootstrap中根据具体的action的需要，启动Zend_Session::start()，然后在action中new Zend_Session_Namespace。]]></description>
		<wfw:commentRss>http://www.jefflei.com/post/113.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>强制使用https的apache设置</title>
		<link>http://www.jefflei.com/post/98.html</link>
		<comments>http://www.jefflei.com/post/98.html#comments</comments>
		<pubDate>Sat, 11 Oct 2008 05:21:25 +0000</pubDate>
		<dc:creator>inetdemon</dc:creator>
				<category><![CDATA[程序开发]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://localhost/wp/?p=98</guid>
		<description><![CDATA[如果我们有一个域，比如login.abc.com, 这个域我们同时接受http和https协议，但是我们希望将http协议的用户重定向到https，可以有两种做法，一种是在代码中进行重定向，zf的代码如下: class Common_Helper_ForceHTTPS extends Zend_Controller_Action_Helper_Abstract {   public function direct() {     if (! isset ( $_SERVER['HTTPS'] ) &#38;&#38; $_SERVER['HTTPS']) {       $request = $this-&#62;getRequest ();       $url = 'https://' . $_SERVER ['HTTP_HOST'] . $request-&#62;getRequestUri ();       $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper ( 'redirector' );       $redirector-&#62;gotoUrl ( $url );     }   } } 还有一种是进行apache配置，由于apache的配置是c代码，效率较高，我们建议用apache的配置来实现。 [...]]]></description>
		<wfw:commentRss>http://www.jefflei.com/post/98.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP安全防范</title>
		<link>http://www.jefflei.com/post/1252.html</link>
		<comments>http://www.jefflei.com/post/1252.html#comments</comments>
		<pubDate>Tue, 07 Oct 2008 17:55:23 +0000</pubDate>
		<dc:creator>inetdemon</dc:creator>
				<category><![CDATA[程序开发]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[互联网安全]]></category>

		<guid isPermaLink="false">http://www.jefflei.com/?p=1252</guid>
		<description><![CDATA[PHP代码安全和XSS，SQL注入等对于各类网站的安全非常中用，尤其是UGC(User Generated Content)网站，论坛和电子商务网站，常常是XSS和SQL注入的重灾区。这里简单介绍一些基本编程要点, 相对系统安全来说，php安全防范更多要求编程人员对用户输入的各种参数能更细心. php编译过程中的安全 建议安装Suhosin补丁，必装安全补丁 php.ini安全设置 register_global = off magic_quotes_gpc = off display_error = off log_error = on # allow_url_fopen = off expose_php = off open_basedir = safe_mode = on disable_function = exec,system,passthru,shell_exec,escapeshellarg,escapeshellcmd,proc_close,proc_open,dl,popen,show_source,get_cfg_var safe_mode_include_dir = DB SQL预处理 mysql_real_escape_string （很多PHPer仍在依靠addslashes防止SQL注入，但是这种方式对中文编码仍然是有问题的。addslashes的问题在于黑客可以用0xbf27来代替单引号，GBK编码中0xbf27不是一个合法字符，因此addslashes只是将0xbf5c27，成为一个有效的多字节字符，其中的0xbf5c仍会被看作是单引号，具体见这篇文章）。用mysql_real_escape_string函数也需要指定正确的字符集，否则依然可能有问题。 prepare + execute(PDO) ZendFramework可以用DB类的quote或者quoteInto, 这两个方法是根据各种数据库实施不用方法的，不会像mysql_real_escape_string只能用于mysql 用户输入的处理 无需保留HTML标签的可以用以下方法 strip_tags, 删除string中所有html标签 htmlspecialchars，只对”&#60;”,”&#62;”,”;”,”’”字符进行转义 htmlentities，对所有html进行转义 必须保留HTML标签情况下可以考虑以下工具： HTML Purifier: HTML [...]]]></description>
		<wfw:commentRss>http://www.jefflei.com/post/1252.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

