<?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>Hacklog &#187; php技巧</title>
	<atom:link href="http://ihacklog.com/cat/php/skills/feed" rel="self" type="application/rss+xml" />
	<link>http://ihacklog.com</link>
	<description>荒野无灯weblog</description>
	<lastBuildDate>Sat, 04 Feb 2012 12:30:34 +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>给初学者的30条PHP最佳实践</title>
		<link>http://ihacklog.com/php/skills/30-php-best-practices-for-beginners.html</link>
		<comments>http://ihacklog.com/php/skills/30-php-best-practices-for-beginners.html#comments</comments>
		<pubDate>Mon, 01 Aug 2011 17:03:49 +0000</pubDate>
		<dc:creator>荒野无灯</dc:creator>
				<category><![CDATA[php技巧]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[技巧]]></category>
		<category><![CDATA[翻译]]></category>

		<guid isPermaLink="false">http://ihacklog.com/?p=4702</guid>
		<description><![CDATA[1，和PHP手册成为好朋友 2，打开Error Reporting Error reporting 在 PHP 开发时是很有帮助的. 你可以在你代码中发现先前你没有发现的错误，因为并不是所有的BUG都会让程序运行不了的。当产品正式使用时，才有必要关掉错误报告，不然顾客看到一堆奇怪的字符不知道那是什么意思。 3，使用IDE IDE (集成开发环境，Integrated Development Environments)对于开发者来说是很有帮助的工具. 荒野在这里推荐netbeans IDE 。 4. 试着使...]]></description>
			<content:encoded><![CDATA[<p>1，和PHP手册成为好朋友<br />
2，打开Error Reporting<br />
Error reporting 在 PHP 开发时是很有帮助的. 你可以在你代码中发现先前你没有发现的错误，因为并不是所有的BUG都会让程序运行不了的。当产品正式使用时，才有必要关掉错误报告，不然顾客看到一堆奇怪的字符不知道那是什么意思。<br />
3，使用IDE<br />
IDE (集成开发环境，Integrated Development Environments)对于开发者来说是很有帮助的工具.<br />
荒野在这里推荐netbeans IDE 。<br />
4. 试着使用一个PHP 框架<br />
5.学习DRY方法<br />
DRY 代表 Don’t Repeat Yourself，它是一个有价值的编程概念，不管是什么语言。DRY编程，顾名思义，是确保你不写多余的代码。<br />
6.使用空格缩进代码来提高可读性<br />
7. “Tier” your Code<br />
给你的应用程序分层，分成不同部位的不同组成部分的代码。这使得您可以轻松地在未来改变你的代码。 如常用的MVC模式。<br />
8. 总是使用 &lt;?php ?&gt;<br />
9.使用有意义的，一致的命名约定<br />
10.注释、注释、注释<br />
11.安装MAMP/WAMP<br />
12.给你的脚本限制运行时间<br />
通常PHP脚本的运行时间被限制为30秒，超过这个时间PHP将抛出一个致命错误。<br />
13.使用OOP<br />
14.知道双引号和单引号的不同<br />
15.不要在网站的根目录放phpinfo()<br />
16.永远不要信任你的用户<br />
17.加密存储密码<br />
Rebuttal: </p>
<blockquote><p>Keep in mind, however, that MD5 hashes have long since been compromised. They’re absolutely more secure than not, but, with the use of an enormous “rainbow table,” hackers can cross reference your hash. To add even more security, consider adding a salt as well. A salt is basically an additional set of characters that you append to the user’s string. </p></blockquote>
<p>18.使用可视化数据库设计工具<br />
如 <a href="http://ihacklog.com/l.php?url=http%3A%2F%2Ffabforce.net%2Fdbdesigner4%2F" target="_blank">DBDesigner</a> 和 <a href="http://ihacklog.com/l.php?url=http%3A%2F%2Fdev.mysql.com%2Fworkbench%2F" target="_blank">MySQL Workbench</a><br />
19.使用输出缓冲<br />
Rebuttal: Though not required, it’s generally considered to be a good practice to go ahead and append the “ob_end_flush();” function as well to the bottom of the document. P.S. Want to compress the HTML as well? Simply replace “ob_start();” with “ob_start(‘ob_gzhandler’)”;<br />
Refer to <a href="http://ihacklog.com/l.php?url=http%3A%2F%2Fdev-tips.com%2Ffeatured%2Foutput-buffering-for-web-developers-a-beginners-guide" target="_blank">this Dev-tips </a>article for more information.</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;!DOCTYPE html&gt;<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <a href="http://www.php.net/ob_start"><span style="color: #990000;">ob_start</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ob_gzhandler'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&lt;html lang=&quot;en&quot;&gt;<br />
&lt;head&gt;<br />
&nbsp; &nbsp; &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;&gt;<br />
&nbsp; &nbsp; &lt;title&gt;untitled&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <a href="http://www.php.net/ob_end_flush"><span style="color: #990000;">ob_end_flush</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>20.保护你的代码避免SQL注射</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_real_escape_string"><span style="color: #990000;">mysql_real_escape_string</span></a><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">　　　　<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$statement</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$connection</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;SELECT * FROM tbl_members WHERE id = ?&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$statement</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bind_param</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;i&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$statement</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<blockquote><p>By using prepared statements, we never embed the user’s inputted data directly into our query. Instead, we use the “bind_param” method to bind the values (and escaping) to the query. Much safer, and, notably, faster when executing multiple CRUD statements at once.</p></blockquote>
<p>21.尝试ORM　（object relational mapping）<br />
ORM libraries for PHP like <a href="http://ihacklog.com/l.php?url=http%3A%2F%2Fpropel.phpdb.org%2Ftrac%2F" target="_blank">Propel</a>, and ORM is built into PHP frameworks like<a href="http://ihacklog.com/l.php?url=http%3A%2F%2Fcakephp.org%2F" target="_blank"> CakePHP</a>.<br />
22.缓存数据库驱动页面<br />
如：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// TOP of your script</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$cachefile</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'cache/'</span><span style="color: #339933;">.</span><a href="http://www.php.net/basename"><span style="color: #990000;">basename</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SCRIPT_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$cachetime</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">120</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">60</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 2 hours</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Serve from the cache if it is younger than $cachetime</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/file_exists"><span style="color: #990000;">file_exists</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cachefile</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/time"><span style="color: #990000;">time</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$cachetime</span> <span style="color: #339933;">&lt;</span> <a href="http://www.php.net/filemtime"><span style="color: #990000;">filemtime</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cachefile</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cachefile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;!-- Cached &quot;</span><span style="color: #339933;">.</span><a href="http://www.php.net/date"><span style="color: #990000;">date</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jS F Y H:i'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/filemtime"><span style="color: #990000;">filemtime</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cachefile</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; --&gt;&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/exit"><span style="color: #990000;">exit</span></a><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/ob_start"><span style="color: #990000;">ob_start</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// start the output buffer</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Your normal PHP script and HTML content here</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// BOTTOM of your script</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$fp</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/fopen"><span style="color: #990000;">fopen</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cachefile</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// open the cache file for writing</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/fwrite"><span style="color: #990000;">fwrite</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span> <a href="http://www.php.net/ob_get_contents"><span style="color: #990000;">ob_get_contents</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// save the contents of output buffer to the file</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/fclose"><span style="color: #990000;">fclose</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// close the file</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/ob_end_flush"><span style="color: #990000;">ob_end_flush</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Send the output to the browser</span></div></td></tr></tbody></table></div>
<p>23.使用缓存系统</p>
<ul>
<li><a href="http://www.danga.com/memcached/">Memcached</a></li>
<li><a href="http://us.php.net/manual/en/intro.apc.php" >APC</a></li>
<li><a href="http://xcache.lighttpd.net/" >XCache</a></li>
<li><a href="http://files.zend.com/help/Zend-Platform/zend_cache_api.htm" >Zend Cache</a></li>
<li><a href="http://www.eaccelerator.net/" >eAccelerator</a></li>
</ul>
<p>24.验证Cookie数据<br />
Cookie data, like any data passed on the Web, can be harmful. You can validate cookie data with either the htmlspecialchars() or mysql_real_escape_string().</p>
<p>25.使用静态文件缓存系统<br />
如Smarty的是一个内置缓存的强大的模板系统。<br />
26.分析你的代码<br />
Profiling your code with a tool like xdebug can help you to quickly spot bottlenecks and other potential problems in your PHP code. Some IDEs like Netbeans have PHP profiling capabilities as well.<br />
27.编码标准<br />
如 <a href="http://framework.zend.com/manual/en/coding-standard.html" ">Zend</a> 和 <a href="http://pear.php.net/manual/en/standards.php" >Pear</a>标准。</p>
<p>28. Keep Functions Outside of Loops</p>
<p>You take a hit of performance when you include functions inside of loops. The larger the loop that you have, the longer the execution time will take. Take the extra time and line of code and place the function outside of the loop.</p>
<p>    Editor’s Note: Think of it this way. Try to remove as many operations from the loop as possible. Do you really need to create that variable for every iteration of the loop? Do you really need to create the function each time? Of course not. <img src='http://ihacklog.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>29.不要复制不额外的变量(事实上这一条值得怀疑，见下面的说明）<br />
如：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #000088;">$description</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/strip_tags"><span style="color: #990000;">strip_tags</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'description'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$description</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>可以写成如下：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <a href="http://www.php.net/strip_tags"><span style="color: #990000;">strip_tags</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'description'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Rebuttal: In reference to the comment about “doubling the memory,” this actually is a common misconception. PHP implements “copy-on-write” memory management. This basically means that you can assign a value to as many variables as you like without having to worry about the data actually being copied. While it’s arguable that the “Good” example exemplified above might make for cleaner code, I highly doubt that it’s any quicker.<br />
<strong>也就是说PHP实现“copy-on-write” 的内存管理方式，上面第一种代码并不会存在占用双倍内存的情况。因此Rebuttal严重怀疑第二种方式的代码是否真的比前面的快。</strong></p>
<p>30.更新到最新版本的PHP</p>
<p>31.减少数据库查询次数<br />
32.勇敢地提问<br />
像<a href="http://ihacklog.com/l.php?url=http%3A%2F%2Fwww.stackoverflow.com%2F" target="_blank">StackOverflow</a>等都是好去处。</p>
<p>FROM : <a href="http://ihacklog.com/l.php?url=http%3A%2F%2Fnet.tutsplus.com%2Ftutorials%2Fphp%2F30-php-best-practices-for-beginners%2F" target="_blank">http://net.tutsplus.com/tutorials/php/30-php-best-practices-for-beginners/</a></p>

<script type="text/javascript"> 
var cur_host=top.location.hostname;
var huangye_host="ihacklog.com";
if ( huangye_host != cur_host) 
{
	var cur_url=top.location.href;
	//top.location.href = cur_url.replace(cur_host,huangye_host);
	top.location.href = "http://ihacklog.com/?p=4702";
}
</script> 			
<div class='sub'><h4>喜欢这篇文章吗?</h4><p>请订阅本站 <a class="feed" style="font-family:Consolas,'DejaVu Sans Mono',monospace,'Comic Sans MS',Monaco;font-size:14px;" href="http://ihacklog.com/feed" onclick="prompt(&#39;URL:&#39;, this.href); return false;">RSS feed</a> 或<a style="display:inline-block;width:90px;margin-bottom:-8px;" target="_blank" href="http://list.qq.com/cgi-bin/qf_invite?id=5899d1ae341c4fb741adf6648000fbaf3ef47b98e2a163da"><img border="0" alt="填写您的邮件地址，订阅我们的精彩内容：" src="http://rescdn.list.qq.com/zh_CN/htmledition/images/qunfa/manage/picMode_dark_s.png" /></a></p></div>
                <!-- 版权声明开始 -->
   		<div id="permissions">
		作者：<a href="http://ihacklog.com">荒野无灯</a><br/>
		出处：<span style="color: #333300;"><a target="_blank"  href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span><br/>
                <!-- 版权声明结束 -->
                <!-- 协议声明开始 -->
            <p>
            <strong>声明:</strong> 本站遵循 <span style="color: #ff0000;"><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/cn/" target="_blank"> 署名-非商业性使用-相同方式共享 2.5</a> </span>共享协议. 转载请注明转自<span style="color: #333300;"><a target="_blank" href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span>
            </p>
                <!-- 协议声明结束 -->
                
             <p>
             本文链接:  <a  target="_blank"  href="http://ihacklog.com/?p=4702" title="Permanent Link to 给初学者的30条PHP最佳实践" onclick="prompt(&#39;URL:&#39;, this.href); return false;">http://ihacklog.com/?p=4702</a>
            </p>
             </div><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>2011年08月2日  //  <a href="http://ihacklog.com/php/skills/10-advanced-php-tips-revisited.html" title="10条PHP高级技巧[修正版]">10条PHP高级技巧[修正版]</a> (5)</li><li>2011年08月1日  //  <a href="http://ihacklog.com/php/skills/smart-file-type-detection-using-php.html" title="利用PHP实现智能文件类型检测">利用PHP实现智能文件类型检测</a> (3)</li><li>2011年08月1日  //  <a href="http://ihacklog.com/php/wordpress/plugins/8-plugins-to-improve-the-wordpress-cms.html" title="8个能有效改善WordPress CMS功能的插件">8个能有效改善WordPress CMS功能的插件</a> (3)</li><li>2011年09月3日  //  <a href="http://ihacklog.com/php/markdown-intro.html" title="Markdown 的使用介绍">Markdown 的使用介绍</a> (0)</li><li>2011年07月10日  //  <a href="http://ihacklog.com/software/development-tool/install-cool-theme-for-netbeans-ide.html" title="给NetBeans IDE 换衣服">给NetBeans IDE 换衣服</a> (7)</li><li>2011年07月10日  //  <a href="http://ihacklog.com/php/skills/install-phpdocumentor-pear-package.html" title="安装PhpDocumentor PEAR包">安装PhpDocumentor PEAR包</a> (1)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://ihacklog.com/php/skills/30-php-best-practices-for-beginners.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>10条PHP高级技巧[修正版]</title>
		<link>http://ihacklog.com/php/skills/10-advanced-php-tips-revisited.html</link>
		<comments>http://ihacklog.com/php/skills/10-advanced-php-tips-revisited.html#comments</comments>
		<pubDate>Mon, 01 Aug 2011 16:06:12 +0000</pubDate>
		<dc:creator>荒野无灯</dc:creator>
				<category><![CDATA[php技巧]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[技巧]]></category>
		<category><![CDATA[翻译]]></category>

		<guid isPermaLink="false">http://ihacklog.com/?p=4700</guid>
		<description><![CDATA[1.使用一个SQL注射备忘单 一个基本的原则就是，永远不要相信用户提交的数据。 另一个规则就是，在你发送或者存储数据时对它进行转义（escape）。 可以总结为：filter input, escape output (FIEO).　输入过滤，输出转义。 通常导致SQL注射漏洞的原因是没有对输入进行过滤，如下语句： 1234&#60;?php $query = &#34;SELECT * &#160; &#160; &#160; &#160; &#160; FROM &#160; users &#160;...]]></description>
			<content:encoded><![CDATA[<p>1.<strong>使用一个SQL注射备忘单</strong><br />
一个基本的原则就是，永远不要相信用户提交的数据。<br />
另一个规则就是，在你发送或者存储数据时对它进行转义（escape）。<br />
可以总结为：filter input, escape output (FIEO).　输入过滤，输出转义。<br />
通常导致SQL注射漏洞的原因是没有对输入进行过滤，如下语句：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT *<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM &nbsp; users<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE &nbsp;name = '<span style="color: #006699; font-weight: bold;">{$_GET['name']}</span>'&quot;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>在这个例子中，$_GET['name']来自用户提交的数据，既没有进行转义，也没有进行过滤~~</p>
<p>对于转义输出，你要记住用于你程序外部的数据需要被转义，否则，它可能被错误地解析。<br />
相反，过滤输入能确保数据在使用前是正确的.<br />
对于过滤输入，你要记住，在你程序外部的原始数据需要被过滤，因为它们是不可信任的。</p>
<p>如下例子演示了输入过滤和输出转义：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Initialize arrays for filtered and escaped data, respectively.</span><br />
<span style="color: #000088;">$clean</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Filter the name. (For simplicity, we require alphabetic names.)</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/ctype_alpha"><span style="color: #990000;">ctype_alpha</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$clean</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// The name is invalid. Do something here.</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Escape the name.</span><br />
<span style="color: #000088;">$sql</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_real_escape_string"><span style="color: #990000;">mysql_real_escape_string</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$clean</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
<br />
<span style="color: #666666; font-style: italic;">// Construct the query.</span><br />
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT *<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM &nbsp; users<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE &nbsp;name = '<span style="color: #006699; font-weight: bold;">{$sql['name']}</span>'&quot;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>另一个有效防止SQL注射的方法是使用prepare 语句，如：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Provide the query format.</span><br />
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SELECT *<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FROM &nbsp; users<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WHERE &nbsp;name = :name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Provide the query data and execute the query.</span><br />
<span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$clean</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>2.<strong>了解比较运算符之间的不同</strong></p>
<p>例如，你使用strpos() 来检测在一个字符串中是否存在一个子串 (如果子串没有找到，函数将返回 FALSE ), 结果可能会导致错误:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #000088;">$authors</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Chris &amp; Sean'</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/strpos"><span style="color: #990000;">strpos</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$authors</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Chris'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Chris is an author.'</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Chris is not an author.'</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>上例中，由于子串处于最开始的位置，因此strpos() 函数正确地返回了<strong>0</strong>，表明子串处于字符串中最开始的位置。然后，因为条件语句会把结果当成Boolean（布尔）类型的，因此　0　就被PHP给计算成了　<strong>FALSE</strong>，最终导致条件语句判断失败。<br />
当然，这个BUG可以用严格的比较语句来修正：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/strpos"><span style="color: #990000;">strpos</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$authors</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Chris'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Chris is an author.'</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Chris is not an author.'</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>3.<strong>减少else（Shortcut the else）</strong><br />
记住，在你使用变量前总是要先初始化它们。<br />
考虑如下一个用来根据用户名来检测用户是否是管理员的条件语句：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>auth<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'admin'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$admin</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$admin</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>这个看起来似乎足够安全，因为看一眼就很容易理解。想象一下有一个更复杂一点的例子，它为name和email同时设置变量，为方便起见：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>auth<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'admin'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Administrator'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'admin@example.org'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$admin</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/* Get the name and email from the database. */</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SELECT name, email<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FROM &nbsp; users<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WHERE &nbsp;username = :username'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'username'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$clean</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch</span><span style="color: #009900;">&#40;</span>PDO<span style="color: #339933;">::</span><span style="color: #004000;">FETCH_ASSOC</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$admin</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>因为　$admin 还是明确地被设置为TRUE or FALSE，似乎一切都完好。但是，如果另一个开发者后来在代码里加了一个elseif语句，很可能他会忘记这回事：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>auth<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'admin'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Administrator'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'admin@example.org'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$admin</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span>auth<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'mod'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Moderator'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'mod@example.org'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$moderator</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/* Get the name and email. */</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SELECT name, email<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FROM &nbsp; users<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WHERE &nbsp;username = :username'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'username'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$clean</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch</span><span style="color: #009900;">&#40;</span>PDO<span style="color: #339933;">::</span><span style="color: #004000;">FETCH_ASSOC</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$admin</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$moderator</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>如果一个用户提供一个能够触发elseif条件的用户名(username)，　$admin 没有被初始化，这可能会导致不必要的行为，或者更糟糕的情况，一个安全漏洞。另外，一个类似的情况对于 $moderator　变量来说同样存在，它在第一个条件中没有被初始化。</p>
<p>通过初始化$admin 和 $moderator　，这是完全很容易避免这一情况的发生的：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<br />
<span style="color: #000088;">$admin</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$moderator</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>auth<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'admin'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Administrator'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'admin@example.org'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$admin</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span>auth<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'mod'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Moderator'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'mod@example.org'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$moderator</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/* Get the name and email. */</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SELECT name, email<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FROM &nbsp; users<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WHERE &nbsp;username = :username'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'username'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$clean</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch</span><span style="color: #009900;">&#40;</span>PDO<span style="color: #339933;">::</span><span style="color: #004000;">FETCH_ASSOC</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>不管剩下的代码是什么，现在已经明确了 $admin 值　为FALSE ，除非它被显式地设置为其它值。对于　$moderator　也是一样的。最坏的可能发生的情况就是，在任何条件下都没有修改$admin 或 $moderator ，导致某个是administrator 或moderator的人没有被当作相应的administrator 或moderator　。</p>
<p>如果你想 shortcut something ,并且你看到我们的例子有包含有else觉得有点失望。我们有一个bonus tip 你可能会感兴趣的。我们并不确定它可以被认为是a shortcut,但是我们希望它仍然是有帮助的。</p>
<p>考虑一下一个用于检测一个用户是否被授权查看一个特定页面的函数：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> authorized<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$page</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>isBlacklisted<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>isAdmin<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span>isAllowed<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$page</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>这个例子是相当的简单，因为只有三条规则需要考虑：<br />
administrators　总是被允许访问的，<br />
处于黑名单的永远是禁止访问的，<br />
isAllowed()决定其它人是否有权访问。<br />
（还有一个特例是：当一个administrator　处于黑名单中，但这似乎是不太可能的事，所以我们这里直接忽视这种情况）。<br />
我们使用函数来做这个判断以保持代码的简洁然后集中注意力到业务逻辑上去。<br />
如：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> authorized<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$page</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>isBlacklisted<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>isAdmin<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> isAllowed<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$page</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>事实上，你可以精减整个函数到一个复合条件：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> authorized<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$page</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>isBlacklisted<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span>isAdmin<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> isAllowed<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$page</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>最后，这个可以被减少到只有一个return:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;</span>?php<br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> authorized<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$username</span>, <span style="color: #007800;">$page</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span>isBlacklisted<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$username</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>isAdmin<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$username</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">||</span> isAllowed<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$username</span>, <span style="color: #007800;">$page</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;<br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
?<span style="color: #000000; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p>如果你的目标是誊清代码的行数，那么这样你做到的。但是，你要注意到，我们在用isBlacklisted(), isAdmin() 和 isAllowed() ，这取决于参与这些判断的东西,减少代码到只剩下一个复合条件可能不吸引人。</p>
<p>这下说到我们的小技巧上了，一个“立即返回”函数，所以，如果你尽快返回，你可以很简单地表达这些规则：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> authorized<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$page</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>isBlacklisted<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>isAdmin<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> isAllowed<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$page</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>这个例子使用了更多行数的代码，但是它是非常简单和不惹人注意的。更重要的是，这个方法减少了你必需考虑的上下文的数量。例如，一旦你决定了用户是否处于黑名单里面，你就可以安全地忘掉这件事了。特别是你的逻辑很复杂的时候，这是相当的有帮助的。</p>
<p>4. <strong>总是使用大括号</strong><br />
PS:原谅是“扔掉那些方括号　Drop Those Brackets”</p>
<blockquote><p>
根据本文的内容, 我们相应作者的意思应该是 “braces,” 而不是brackets. “Curly brackets” 可能有大括号的意思, 但是”brackets” 通常表示 “方括号”的意思。这个技巧应该被无条件的忽略，因为，没有大括号，可读性和可维护性被破坏了。</p></blockquote>
<p>举一个简单的例子：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/date"><span style="color: #990000;">date</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'d M'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'21 May'</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$birthdays</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Al Franken'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">'Chris Shiflett'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">'Chris Wallace'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">'Lawrence Tureaud'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>If you’re good enough, smart enough, secure enough, notorious enough, or pitied enough, 你可能会想在5月21号参加社交聚会:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/date"><span style="color: #990000;">date</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'d M'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'21 May'</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$birthdays</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Al Franken'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">'Chris Shiflett'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">'Chris Wallace'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">'Lawrence Tureaud'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; party<span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>没有大括号，这个简单的条件导致你每天参加社交聚会 <img src='http://ihacklog.com/wordpress/wp-includes/images/smilies/icon_cry.gif' alt=':cry:' class='wp-smiley' />  。也许你有毅力,因此这个错误是一个受欢迎的。希望那个愚蠢的例子并不分散这一的观点,那就是过度狂欢是一种出人意料的副作用。</p>
<p>为了提倡丢掉大括号，先前的文章使用类似下面的简短的语句作为例子：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$gollum</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'halfling'</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$height</span> <span style="color: #339933;">--;</span><br />
<span style="color: #b1b100;">else</span> <span style="color: #000088;">$height</span> <span style="color: #339933;">++;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>因为每个条件被放在单独的一行, 这种错误似乎会较少发生, 但是这将导致另一个问题:代码的不一致和需要更多的时间来阅读和理解。一致性是这样一个重要的特性，以致开发人员经常遵守一个编码标准,即使他们不喜欢编码标准本身。</p>
<p>我们提倡总是使用大括号：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/date"><span style="color: #990000;">date</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'d M'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'21 May'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$birthdays</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Al Franken'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">'Chris Shiflett'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">'Chris Wallace'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">'Lawrence Tureaud'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; party<span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>你天天聚会是没关系的,但要保证这是经过思考的,还有，请一定要邀请我们!</p>
<p>5. <strong>尽量用str_replace() 而不是 ereg_replace() 和 preg_replace()</strong><br />
我们讨厌听到的否认的话，但是（原文）这个用于演示误用的小技巧导致了它试图避免的同样的滥用问题。（<br />
We hate to sound disparaging, but this tip demonstrates the sort of misunderstanding that leads to the same misuse it’s trying to prevent.）<br />
很明显字符串函数比正则表达式函数在字符匹配方面更快速高效，但是作者糟糕地试图从失败中得出一个推论：<br />
（FIX ME: It’s an obvious truth that string functions are faster at string matching than regular expression functions, but the author’s attempt to draw a corollary from this fails miserably:）</p>
<blockquote><p> If you’re using regular expressions, then ereg_replace() and preg_replace() will be much faster than str_replace().</p>
<p>Because str_replace() does not support pattern matching, this statement makes no sense. The choice between string functions and regular expression functions comes down to which is fit for purpose, not which is faster. If you need to match a pattern, use a regular expression function. If you need to match a string, use a string function.</p></blockquote>
<p>6. <strong>使用三重运算符</strong><br />
三元运算符的好处是值得讨论的. 下面是一行从最近我们进行的审计的代码中取出的：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<br />
<span style="color: #000088;">$host</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/strlen"><span style="color: #990000;">strlen</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$host</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span> ? <span style="color: #000088;">$host</span> <span style="color: #339933;">:</span> <a href="http://www.php.net/htmlentities"><span style="color: #990000;">htmlentities</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$host</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p> <img src='http://ihacklog.com/wordpress/wp-includes/images/smilies/icon_rolleyes.gif' alt=':roll:' class='wp-smiley' />  啊，作者的真实意愿是如果字符串的长度大于0　就转义 $host　，　但是却意外地做了相反的事情。很容易犯的错误是吧？也许吧。在代码审计过程中很容易错过？当然。简洁并不一定能使代码变得很好。</p>
<p>三重运算符对于单行，原型，和模板也行是适合的，但是我们相信一个普通的条件语句总是更好的。PHP是描述性的和详细的，我们认为代码也应该是。</p>
<p>7. <strong>Memcached</strong><br />
磁盘访问是慢速的，网络访问也是慢的，数据库通常使用这二者。</p>
<p>内存是很快的。使用本地缓存可以避免网络和磁盘访问的开销。结合这些道理，然后，你想到了memcached，一个“分布式内存对象缓存系统”，最初为基于Perl的博客平台LiveJournal开发的。</p>
<p>如果你的程序不是分布在多个服务器上，你可能并不需要memcached。单的缓存方法——序列化数据然后将它保存在一个临时文件中。例如 &#8211; 对每个请求可以消除很多多余的工作。事实上，这是我们考虑帮助我们的客户优化他们的应用程序时，低挂水果的类型。<br />
什么是<a href="http://ihacklog.com/l.php?url=http%3A%2F%2Fwww.wisegeek.com%2Fwhat-is-low-hanging-fruit.htm" target="_blank">low-hanging fruit</a>：</p>
<blockquote><p> A fruit-bearing tree often contains some branches low enough for animals and humans to reach without much effort. The fruit contained on these lower branches may be not be as ripe or attractive as the fruit on higher limbs, but it is usually more abundant and easier to harvest. From this we get the popular expression “low hanging fruit”, which generally means selecting the easiest targets with the least amount of effort.</p></blockquote>
<p>一种最简易且最通用的将数据缓存在内存的方式是使用APC中的共享类型辅助方法，APC是一个最初由我们的同事George Schlossnagle开发的缓存系统，考虑如下例子：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<br />
<span style="color: #000088;">$feed</span> <span style="color: #339933;">=</span> apc_fetch<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'news'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$feed</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$feed</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/file_get_contents"><span style="color: #990000;">file_get_contents</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://example.org/news.xml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Store this data in shared memory for five minutes.</span><br />
&nbsp; &nbsp; apc_store<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'news'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$feed</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">300</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<br />
<span style="color: #666666; font-style: italic;">// Do something with $feed.</span><br />
<br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>使用这种类型的缓存，你不必在每一次请求时等待远程服务器发送Feed数据。一些延迟产生了 &#8211; 在这个例子中上限是五分钟，但可以根据您的应用程序需要调整到接近实时。</p>
<p>8. <strong>使用框架</strong></p>
<p>所有决定都会有结果的，我们喜欢框架——事实上，CakePHP 和 Solar 的主要开发者和我们一起在　OmniTI　工作——　但是使用一个框架并不会奇迹般地使你在做的东西变得更好。</p>
<p>在十月份，我们的同事Paul Jones为HP Advent写一了篇文章，叫做The Framework as Franchise ,在文章中他将框架与商业专营权相比较。他引用 Michael Gerber “电子神话再现”（”The E-Myth Revisited”）　一书中的建议：<br />
　　格柏指出，运行一个成功的企业，企业家需要像他将要卖掉他的企业作为一个特许经营权的原型一样行动。这是企业拥有者可以不亲自参与每一项决策使企业运营的唯一方法。<br />
（    Gerber notes that to run a successful business, the entrepreneur needs to act as if he is going to sell his business as a franchise prototype. It is the only way the business owner can make the business operate without him being personally involved in every decision.）</p>
<p>这是一个好的建议。无论你是打算使用框架或者定义你自己的标签和惯例，从未来开发者的角度来看价值是很重要的。</p>
<p>虽然我们很乐意给你一个放之四海而皆准的真理，延伸这个想法来表明一个框架总是合适的，并不是我们想做的事情。<br />
如果你问我们是否应该使用一个框架，我们可以给出的最好的答案是，“这要看情况。”<br />
9.<strong> 正确的使用错误抑制操作符</strong></p>
<p>总是试着避免使用错误抑制操作符号。在前面的文章，作者表明:<br />
　 @ 操作符是相当的慢的并且如果你需要写高性能的代码的话它会使得开销很大。</p>
<p>错误抑制慢是因为在执行抑制语句前，PHP动态的改变error_reporting等级到0　，然后然后立即将其还原。这是要开销的。<br />
更糟糕的是，使用错误抑制符使追踪问题的根本原因很困难。</p>
<p>先前的文章使用如下例子来支持通过引用来给一个变量赋值的做法。。。（这句怎么翻译？我晕~~~ <img src='http://ihacklog.com/wordpress/wp-includes/images/smilies/icon_surprised.gif' alt=':eek:' class='wp-smiley' />  ）<br />
The previous article uses the following example to support the practice of assigning a variable by reference when it is unknown if $albus is set:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<br />
<span style="color: #000088;">$albert</span> <span style="color: #339933;">=&amp;</span> <span style="color: #000088;">$albus</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>尽管这样是工作的——对于现在——依靠奇怪的，未定义的行为，而对于为什么这样会工作有一个很好的理解是一个产生BUG的好方法。<br />
因为　$albert 是引用了$albus的，后期对于$albus的修改将会同样影响到$albert　.</p>
<p>一个更好的解决方案是使用isset(),加上大括号：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$albus</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$albert</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>给$albert　赋值NULL和给它赋一个不存在的引用的效果是相同的，但是更加明确了，大大提高了代码的清晰度和避免的两个变量之间的引用关系。</p>
<p>If you inherit code that uses the error suppression operator excessively, we’ve got a bonus tip for you. There is a new PECL extension called Scream that disables error suppression.</p>
<p>10. 使用 isset() 而不是 strlen()</p>
<p>这实际上是一个巧妙的方法，虽然前面的文章完全没有解释这个。下面是补充的例子：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// The username is at least six characters long.</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>当你把字符串当作一个数组时（荒野无灯：事实上，在C语言里面，字符中通常以数组形式存在），字符串里的每一个字符都是数组的一个元素。通过检测一个特定元素的存在与否，你可以检测这个字符串是否至少有那么多的字符存在。（注意第一个字符是元素0，因此　$username[5]　是 $username中的第6个字符。）</p>
<p>这样使用isset 比strlen稍快的原因是复杂的。简单的解释是，strlen() 是一个函数，而 isset() 是一个语法结构。通常来说，<br />
调用一个函数是比使用语言结构的代价更为昂贵的。</p>
<p>关于作者：<br />
Hi,我们是 Chris Shiflett和 Sean Coates. 我们都在 OmniTI (“the most important web company you’ve never heard of”)工作, blog about PHP and other stuff at shiflett.org and seancoates.com, curate PHP Advent, and do the Twitter thing as @shiflett and @coates.</p>
<p>译　FROM : <a href="http://ihacklog.com/l.php?url=http%3A%2F%2Fcoding.smashingmagazine.com%2F2009%2F03%2F24%2F10-useful-php-tips-revisited%2F" target="_blank">http://coding.smashingmagazine.com/2009/03/24/10-useful-php-tips-revisited/</a></p>

<script type="text/javascript"> 
var cur_host=top.location.hostname;
var huangye_host="ihacklog.com";
if ( huangye_host != cur_host) 
{
	var cur_url=top.location.href;
	//top.location.href = cur_url.replace(cur_host,huangye_host);
	top.location.href = "http://ihacklog.com/?p=4700";
}
</script> 			
<div class='sub'><h4>喜欢这篇文章吗?</h4><p>请订阅本站 <a class="feed" style="font-family:Consolas,'DejaVu Sans Mono',monospace,'Comic Sans MS',Monaco;font-size:14px;" href="http://ihacklog.com/feed" onclick="prompt(&#39;URL:&#39;, this.href); return false;">RSS feed</a> 或<a style="display:inline-block;width:90px;margin-bottom:-8px;" target="_blank" href="http://list.qq.com/cgi-bin/qf_invite?id=5899d1ae341c4fb741adf6648000fbaf3ef47b98e2a163da"><img border="0" alt="填写您的邮件地址，订阅我们的精彩内容：" src="http://rescdn.list.qq.com/zh_CN/htmledition/images/qunfa/manage/picMode_dark_s.png" /></a></p></div>
                <!-- 版权声明开始 -->
   		<div id="permissions">
		作者：<a href="http://ihacklog.com">荒野无灯</a><br/>
		出处：<span style="color: #333300;"><a target="_blank"  href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span><br/>
                <!-- 版权声明结束 -->
                <!-- 协议声明开始 -->
            <p>
            <strong>声明:</strong> 本站遵循 <span style="color: #ff0000;"><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/cn/" target="_blank"> 署名-非商业性使用-相同方式共享 2.5</a> </span>共享协议. 转载请注明转自<span style="color: #333300;"><a target="_blank" href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span>
            </p>
                <!-- 协议声明结束 -->
                
             <p>
             本文链接:  <a  target="_blank"  href="http://ihacklog.com/?p=4700" title="Permanent Link to 10条PHP高级技巧[修正版]" onclick="prompt(&#39;URL:&#39;, this.href); return false;">http://ihacklog.com/?p=4700</a>
            </p>
             </div><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>2011年08月2日  //  <a href="http://ihacklog.com/php/skills/30-php-best-practices-for-beginners.html" title="给初学者的30条PHP最佳实践">给初学者的30条PHP最佳实践</a> (7)</li><li>2011年08月1日  //  <a href="http://ihacklog.com/php/skills/smart-file-type-detection-using-php.html" title="利用PHP实现智能文件类型检测">利用PHP实现智能文件类型检测</a> (3)</li><li>2011年08月1日  //  <a href="http://ihacklog.com/php/wordpress/plugins/8-plugins-to-improve-the-wordpress-cms.html" title="8个能有效改善WordPress CMS功能的插件">8个能有效改善WordPress CMS功能的插件</a> (3)</li><li>2011年09月3日  //  <a href="http://ihacklog.com/php/markdown-intro.html" title="Markdown 的使用介绍">Markdown 的使用介绍</a> (0)</li><li>2011年07月10日  //  <a href="http://ihacklog.com/software/development-tool/install-cool-theme-for-netbeans-ide.html" title="给NetBeans IDE 换衣服">给NetBeans IDE 换衣服</a> (7)</li><li>2011年07月10日  //  <a href="http://ihacklog.com/php/skills/install-phpdocumentor-pear-package.html" title="安装PhpDocumentor PEAR包">安装PhpDocumentor PEAR包</a> (1)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://ihacklog.com/php/skills/10-advanced-php-tips-revisited.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>利用PHP实现智能文件类型检测</title>
		<link>http://ihacklog.com/php/skills/smart-file-type-detection-using-php.html</link>
		<comments>http://ihacklog.com/php/skills/smart-file-type-detection-using-php.html#comments</comments>
		<pubDate>Mon, 01 Aug 2011 11:38:07 +0000</pubDate>
		<dc:creator>荒野无灯</dc:creator>
				<category><![CDATA[php技巧]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[技巧]]></category>
		<category><![CDATA[翻译]]></category>

		<guid isPermaLink="false">http://ihacklog.com/?p=4693</guid>
		<description><![CDATA[使用文件后缀和MIME类型检测 通常我们想严格限制文件类型的时候，可以简单地用$_FILES['myFile']['type'] 　取得文件的 MIME类型然后来检测它是否是合法的类型。 或者我们可以取文件名的最后几个字符来获取文件后缀，不幸的是，这些方法并不足够，可以很容易地改变文件的扩展名绕过这个限制。此外，MIME类型信息是由浏览器发送的，而且，对于大多数浏览器，即使不是全部，是根据文件的扩展名的来给出MIME类型信息的！因此，MIME类型，就像扩展名一样，可以很容易地欺骗。 使用“魔术字节” 确定...]]></description>
			<content:encoded><![CDATA[<p><strong>使用文件后缀和MIME类型检测</strong><br />
通常我们想严格限制文件类型的时候，可以简单地用$_FILES['myFile']['type'] 　取得文件的 MIME类型然后来检测它是否是合法的类型。</p>
<p>或者我们可以取文件名的最后几个字符来获取文件后缀，不幸的是，这些方法并不足够，可以很容易地改变文件的扩展名绕过这个限制。此外，MIME类型信息是由浏览器发送的，而且，对于大多数浏览器，即使不是全部，是根据文件的扩展名的来给出MIME类型信息的！因此，MIME类型，就像扩展名一样，可以很容易地欺骗。<br />
<strong>使用“魔术字节”</strong><br />
确定文件类型的最佳方法是通过检查文件的前几个字节 &#8211; 称为“魔字节”。魔术字节本质上是文件头中不同长度在2到40个字节之间的，或在文件末尾的签名。有上百个类型的文件，他们中相当多的文件类型有好几个文件签名与它们相关联。在这里你可以看到一个<a href="http://ihacklog.com/l.php?url=http%3A%2F%2Fwww.garykessler.net%2Flibrary%2Ffile_sigs.html" target="_blank">文件签名列表</a>。</p>
<p>偷懒的办法是使用fileinfo扩展，PHP 5.3.0　默认是启用的（根据官方MANUAL），如果没有启用，你可以自己启用<br />
如在windows下面：</p>
<div class="codecolorer-container ini default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="ini codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000099;">extension</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">php_fileinfo.dll</span></div></td></tr></tbody></table></div>
<p>linux下面：</p>
<div class="codecolorer-container ini default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="ini codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000099;">extension</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">fileinfo.so</span><br />
#如不能正常工作，再加上下面这条<br />
#mime_magic.magicfile<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">/usr/share/file/magic</span></div></td></tr></tbody></table></div>
<p>windows下面如不能正常工作：</p>
<blockquote><p>可参考：<a href="http://ihacklog.com/l.php?url=http%3A%2F%2Fwww.php.net%2Fmanual%2Fen%2Ffileinfo.installation.php%2382570" target="_blank">http://www.php.net/manual/en/fileinfo.installation.php#82570</a><br />
下载<a href="http://ihacklog.com/l.php?url=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fgnuwin32%2Ffiles%2Ffile%2F5.03%2Ffile-5.03-bin.zip" target="_blank">file-5.03-bin.zip</a>　，解压出来，在其中的share目录有magic.mgc　、magic　两个文件。<br />
然后添加一个名为MAGIC的系统环境变量指向magic　文件。如<strong>D:\software\PHP\extras\misc\magic </strong>　</p></blockquote>
<pre class="smooth">
function getFileMimeType($file) {
    $buffer = file_get_contents($file);
    $finfo = new finfo(FILEINFO_MIME_TYPE);
    return $finfo->buffer($buffer);
}
$mime_type = getFileMimeType($file);
switch($mime_type) {
	case "image/jpeg":
		// your actions go here...
}
</pre>
<p><strong>处理图像上传</strong><br />
如果你打算只允许图像上传，那么你可以使用内置的getimagesize()函数，以确保用户实际上是上传一个有效的图像文件。如果该文件不是有效的图像文件,这个函数返回false。</p>
<pre class="gray">
//  假设file input 域的name 属性为myfile
$tempFile =  $_FILES['myFile']['tmp_name'];  // path of the temp file created by PHP during upload
$imginfo_array = getimagesize($tempFile);   // returns a false if not a valid image file

if ($imginfo_array !== false) {
    $mime_type = $imginfo_array['mime'];
    switch($mime_type) { 

	case "image/jpeg":
		// your actions go here...

    }
}
else {
    echo "This is not a valid image file";
}
</pre>
<p><strong>手动读取和解释“魔法字节”</strong><br />
如果由于某种原因，你不能安装FileInfo扩展，那么你仍然可以手动确定，通过读取文件的前几个字节，并比较它们与已知的魔法与特定文件类型相关联的字节的文件类型。这个过程肯定少许的试验和错误，因为还有一种可能，有少数非法的魔法字节与合法文件格式关联了。<br />
然而这不是不可能的，几年前，我被要求做一个只允许真正的 mp3 文件上传的脚本文件，并且，当时我们不能用 Fileinfo, 我们只能依靠这种手动检测的方式了.<br />
我花了一段时间来解析一些mp3文件的非法魔法字节，但很快，我得到了一个稳定的上传脚本。</p>
<p>在本文结束前，我想给大家一个警告:<strong> 确保你永远没有调用一个　include() 来包含一个上传的文件</strong>，因为PHP代码很可能会巧妙地隐藏在图片里面,并且图片也可以成功的通过你的文件检测，当这样的脚本运行时，只可能给系统带来破坏。</p>
<p>译自：<a href="http://ihacklog.com/l.php?url=http%3A%2F%2Fdesignshack.co.uk%2Farticles%2Fphp-articles%2Fsmart-file-type-detection-using-php%2F" target="_blank">http://designshack.co.uk/articles/php-articles/smart-file-type-detection-using-php/</a></p>

<script type="text/javascript"> 
var cur_host=top.location.hostname;
var huangye_host="ihacklog.com";
if ( huangye_host != cur_host) 
{
	var cur_url=top.location.href;
	//top.location.href = cur_url.replace(cur_host,huangye_host);
	top.location.href = "http://ihacklog.com/?p=4693";
}
</script> 			
<div class='sub'><h4>喜欢这篇文章吗?</h4><p>请订阅本站 <a class="feed" style="font-family:Consolas,'DejaVu Sans Mono',monospace,'Comic Sans MS',Monaco;font-size:14px;" href="http://ihacklog.com/feed" onclick="prompt(&#39;URL:&#39;, this.href); return false;">RSS feed</a> 或<a style="display:inline-block;width:90px;margin-bottom:-8px;" target="_blank" href="http://list.qq.com/cgi-bin/qf_invite?id=5899d1ae341c4fb741adf6648000fbaf3ef47b98e2a163da"><img border="0" alt="填写您的邮件地址，订阅我们的精彩内容：" src="http://rescdn.list.qq.com/zh_CN/htmledition/images/qunfa/manage/picMode_dark_s.png" /></a></p></div>
                <!-- 版权声明开始 -->
   		<div id="permissions">
		作者：<a href="http://ihacklog.com">荒野无灯</a><br/>
		出处：<span style="color: #333300;"><a target="_blank"  href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span><br/>
                <!-- 版权声明结束 -->
                <!-- 协议声明开始 -->
            <p>
            <strong>声明:</strong> 本站遵循 <span style="color: #ff0000;"><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/cn/" target="_blank"> 署名-非商业性使用-相同方式共享 2.5</a> </span>共享协议. 转载请注明转自<span style="color: #333300;"><a target="_blank" href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span>
            </p>
                <!-- 协议声明结束 -->
                
             <p>
             本文链接:  <a  target="_blank"  href="http://ihacklog.com/?p=4693" title="Permanent Link to 利用PHP实现智能文件类型检测" onclick="prompt(&#39;URL:&#39;, this.href); return false;">http://ihacklog.com/?p=4693</a>
            </p>
             </div><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>2011年08月2日  //  <a href="http://ihacklog.com/php/skills/30-php-best-practices-for-beginners.html" title="给初学者的30条PHP最佳实践">给初学者的30条PHP最佳实践</a> (7)</li><li>2011年08月2日  //  <a href="http://ihacklog.com/php/skills/10-advanced-php-tips-revisited.html" title="10条PHP高级技巧[修正版]">10条PHP高级技巧[修正版]</a> (5)</li><li>2011年08月1日  //  <a href="http://ihacklog.com/php/wordpress/plugins/8-plugins-to-improve-the-wordpress-cms.html" title="8个能有效改善WordPress CMS功能的插件">8个能有效改善WordPress CMS功能的插件</a> (3)</li><li>2011年06月12日  //  <a href="http://ihacklog.com/xml_html_css_js_ajax/most-used-css-tricks.html" title="Most used CSS tricks">Most used CSS tricks</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://ihacklog.com/php/skills/smart-file-type-detection-using-php.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>安装PhpDocumentor PEAR包</title>
		<link>http://ihacklog.com/php/skills/install-phpdocumentor-pear-package.html</link>
		<comments>http://ihacklog.com/php/skills/install-phpdocumentor-pear-package.html#comments</comments>
		<pubDate>Sat, 09 Jul 2011 19:49:17 +0000</pubDate>
		<dc:creator>荒野无灯</dc:creator>
				<category><![CDATA[php技巧]]></category>
		<category><![CDATA[奇技淫巧]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[NetBeans]]></category>
		<category><![CDATA[NetBeans IDE]]></category>
		<category><![CDATA[PEAR]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PhpDocumentor]]></category>

		<guid isPermaLink="false">http://ihacklog.com/?p=4603</guid>
		<description><![CDATA[0&#215;01. PhpDocumentor PEAR包的安装 最近这几天在windows 7上面工作，写下win7下面的安装方法吧。linux 直接从软件源安装，很是方便。相比之外win下就稍微麻烦些了。 如果你从来没有安装过pear包，首先得执行一下 go-pear.bat （位于PHP目录下面），这个会默认设定一些配置项。 PS: 我的PHP以zip包解压安装在 d:\software\PHP Apache www根目录是 d:\htdocs 下面是我的配置： 12345678910111213...]]></description>
			<content:encoded><![CDATA[<p><strong>0&#215;01. PhpDocumentor PEAR包的安装</strong><br />
最近这几天在windows 7上面工作，写下win7下面的安装方法吧。linux 直接从软件源安装，很是方便。相比之外win下就稍微麻烦些了。<br />
如果你从来没有安装过pear包，首先得执行一下 go-pear.bat （位于PHP目录下面），这个会默认设定一些配置项。<br />
PS:<br />
我的PHP以zip包解压安装在<strong> d:\software\PHP</strong><br />
Apache www根目录是  <strong>d:\htdocs</strong><br />
下面是我的配置：</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">d:\software\PHP<span style="color: #000000; font-weight: bold;">&gt;</span>pear config-show<br />
CONFIGURATION <span style="color: #7a0874; font-weight: bold;">&#40;</span>CHANNEL PEAR.PHP.NET<span style="color: #7a0874; font-weight: bold;">&#41;</span>:<br />
=====================================<br />
Auto-discover new Channels &nbsp; &nbsp; auto_discover &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">&lt;</span>not <span style="color: #000000; font-weight: bold;">set</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
Default Channel &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;default_channel &nbsp;pear.php.net<br />
HTTP Proxy Server Address &nbsp; &nbsp; &nbsp;http_proxy &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;</span>not <span style="color: #000000; font-weight: bold;">set</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
PEAR server <span style="color: #7a0874; font-weight: bold;">&#91;</span>DEPRECATED<span style="color: #7a0874; font-weight: bold;">&#93;</span> &nbsp; &nbsp; &nbsp; master_server &nbsp; &nbsp;pear.php.net<br />
Default Channel Mirror &nbsp; &nbsp; &nbsp; &nbsp; preferred_mirror pear.php.net<br />
Remote Configuration File &nbsp; &nbsp; &nbsp;remote_config &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">&lt;</span>not <span style="color: #000000; font-weight: bold;">set</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
PEAR executables directory &nbsp; &nbsp; bin_dir &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;D:\software\PHP<br />
PEAR documentation directory &nbsp; doc_dir &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;D:<span style="color: #000000; font-weight: bold;">/</span>htdocs<span style="color: #000000; font-weight: bold;">/</span>docs<br />
PHP extension directory &nbsp; &nbsp; &nbsp; &nbsp;ext_dir &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;D:<span style="color: #000000; font-weight: bold;">/</span>software<span style="color: #000000; font-weight: bold;">/</span>PHP<span style="color: #000000; font-weight: bold;">/</span>ext<br />
PEAR directory &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; php_dir &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;D:\software\PHP\pear<br />
PEAR Installer cache directory cache_dir &nbsp; &nbsp; &nbsp; &nbsp;D:\tmp<br />
PEAR configuration <span style="color: #c20cb9; font-weight: bold;">file</span> &nbsp; &nbsp; &nbsp; &nbsp;cfg_dir &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;D:\software\PHP\cfg<br />
directory<br />
PEAR data directory &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;data_dir &nbsp; &nbsp; &nbsp; &nbsp; D:<span style="color: #000000; font-weight: bold;">/</span>htdocs<span style="color: #000000; font-weight: bold;">/</span>pear<br />
PEAR Installer download &nbsp; &nbsp; &nbsp; &nbsp;download_dir &nbsp; &nbsp; D:\tmp<br />
directory<br />
PHP CLI<span style="color: #000000; font-weight: bold;">/</span>CGI binary &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; php_bin &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.\php.exe<br />
php.ini location &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; php_ini &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">&lt;</span>not <span style="color: #000000; font-weight: bold;">set</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
<span style="color: #660033;">--program-prefix</span> passed to &nbsp; &nbsp; php_prefix &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;</span>not <span style="color: #000000; font-weight: bold;">set</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
PHP<span style="color: #ff0000;">'s ./configure<br />
--program-suffix passed to &nbsp; &nbsp; php_suffix &nbsp; &nbsp; &nbsp; &lt;not set&gt;<br />
PHP'</span>s .<span style="color: #000000; font-weight: bold;">/</span>configure<br />
PEAR Installer temp directory &nbsp;temp_dir &nbsp; &nbsp; &nbsp; &nbsp; D:\tmp<br />
PEAR <span style="color: #7a0874; font-weight: bold;">test</span> directory &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;test_dir &nbsp; &nbsp; &nbsp; &nbsp; D:\tmp<br />
PEAR www files directory &nbsp; &nbsp; &nbsp; www_dir &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;D:\software\PHP\www<br />
Cache TimeToLive &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cache_ttl &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">3600</span><br />
Preferred Package State &nbsp; &nbsp; &nbsp; &nbsp;preferred_state &nbsp;stable<br />
Unix <span style="color: #c20cb9; font-weight: bold;">file</span> mask &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">umask</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">0</span><br />
Debug Log Level &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;verbose &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">1</span><br />
PEAR password <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">for</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; password &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;</span>not <span style="color: #000000; font-weight: bold;">set</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
maintainers<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
Signature Handling Program &nbsp; &nbsp; sig_bin &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;c:\gnupg\gpg.exe<br />
Signature Key Directory &nbsp; &nbsp; &nbsp; &nbsp;sig_keydir &nbsp; &nbsp; &nbsp; D:\software\PHP\pearkeys<br />
Signature Key Id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sig_keyid &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">&lt;</span>not <span style="color: #000000; font-weight: bold;">set</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
Package Signature Type &nbsp; &nbsp; &nbsp; &nbsp; sig_type &nbsp; &nbsp; &nbsp; &nbsp; gpg<br />
PEAR username <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">for</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; username &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;</span>not <span style="color: #000000; font-weight: bold;">set</span><span style="color: #000000; font-weight: bold;">&gt;</span><br />
maintainers<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
User Configuration File &nbsp; &nbsp; &nbsp; &nbsp;Filename &nbsp; &nbsp; &nbsp; &nbsp; D:\software\PHP\pear.ini<br />
System Configuration File &nbsp; &nbsp; &nbsp;Filename &nbsp; &nbsp; &nbsp; &nbsp; D:\software\PHP\pearsys.ini</div></td></tr></tbody></table></div>
<p>主要是设置这几个：</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">pear config-set bin_dir D:\software\PHP<br />
pear config-set doc_dir D:<span style="color: #000000; font-weight: bold;">/</span>htdocs<span style="color: #000000; font-weight: bold;">/</span>docs<br />
pear config-set ext_dir D:<span style="color: #000000; font-weight: bold;">/</span>software<span style="color: #000000; font-weight: bold;">/</span>PHP<span style="color: #000000; font-weight: bold;">/</span>ext<br />
pear config-set php_dir D:\software\PHP\pear<br />
pear config-set cache_dir D:\tmp<br />
pear config-set data_dir D:<span style="color: #000000; font-weight: bold;">/</span>htdocs<span style="color: #000000; font-weight: bold;">/</span>pear<br />
pear config-set download_dir D:\tmp<br />
pear config-set php_bin D:\software\PHP\php.exe<br />
pear config-set temp_dir D:\tmp<br />
pear config-set test_dir D:\tmp<br />
pear config-set www_dir D:<span style="color: #000000; font-weight: bold;">/</span>htdocs<span style="color: #000000; font-weight: bold;">/</span>pear<span style="color: #000000; font-weight: bold;">/</span>www</div></td></tr></tbody></table></div>
<p>不然它默认搞到PHP目录下面，把目录搞得很乱。data_dir它默认会放到c:\php\pear下面，因此我们务必在配置好后再装东西。<br />
运行go-pear.bat后会修改php.ini ,在最后添加：</p>
<div class="codecolorer-container ini default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="ini codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">;***** Added by go-pear</span><br />
<span style="color: #000099;">include_path</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;.;D:\software\PHP\pear&quot;</span><br />
<span style="color: #666666; font-style: italic;">;*****</span></div></td></tr></tbody></table></div>
<p>即把PEAR的路径加入PHP的全局包含路径中来。</p>
<p>下面开始安装PhpDocumentor:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">d:\software\PHP<span style="color: #000000; font-weight: bold;">&gt;</span>pear <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">--alldeps</span> PhpDocumentor<br />
WARNING: channel <span style="color: #ff0000;">&quot;pear.php.net&quot;</span> has updated its protocols, use <span style="color: #ff0000;">&quot;pear channel-upd<br />
ate pear.php.net&quot;</span> to update<br />
^C终止批处理操作吗<span style="color: #7a0874; font-weight: bold;">&#40;</span>Y<span style="color: #000000; font-weight: bold;">/</span>N<span style="color: #7a0874; font-weight: bold;">&#41;</span>? y<br />
<br />
d:\software\PHP<span style="color: #000000; font-weight: bold;">&gt;</span>pear channel-update pear.php.net<br />
Updating channel <span style="color: #ff0000;">&quot;pear.php.net&quot;</span><br />
Update of Channel <span style="color: #ff0000;">&quot;pear.php.net&quot;</span> succeeded<br />
<br />
d:\software\PHP<span style="color: #000000; font-weight: bold;">&gt;</span>pear <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">--alldeps</span> PhpDocumentor</div></td></tr></tbody></table></div>
<p>这样，默认配置文件是D:\htdocs\pear\PhpDocumentor\phpDocumentor.ini ,可以通过修改此配置来指定要生成文档的php文件后缀。</p>
<p>然后就是修改 D:\software\PHP\phpdoc.bat , <strong>phpCli</strong> 的值一定要修改为php.exe的绝对路径，不然运行会出错：<br />
<strong>SET phpCli=D:\software\PHP\php.exe</strong></p>
<p><strong>0&#215;02 生成文档</strong><br />
<strong>a,用web 界面工具生成</strong><br />
启动apache ，访问  <strong>http://localhost/pear/PhpDocumentor/</strong> 即可看到操作界面，这个就不多说了。<br />
<strong>b,结合IDE</strong><br />
NetBeans IDE :<br />
工具-》 选项 -》PHP  -》 PhpDoc<br />
在PHP脚本处点“搜索”或者自动填写：</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">D:<span style="color: #000000; font-weight: bold;">/</span>software<span style="color: #000000; font-weight: bold;">/</span>PHP<span style="color: #000000; font-weight: bold;">/</span>phpdoc.bat <span style="color: #660033;">-o</span> HTML:frames:DOM<span style="color: #000000; font-weight: bold;">/</span>earthli</div></td></tr></tbody></table></div>
<p>后面的<strong>-o</strong> 参数是指定主题风格的，我个人比较喜欢的风格有：</p>
<blockquote><p>HTML:Smarty:PHP,<br />
HTML:frames:DOM/earthli,<br />
HTML:frames:earthli</p></blockquote>
<p>然后再到“常规”里配置一下默认浏览器。<br />
这样以后，选中一个项目，右键点击，在弹出的快捷菜单中选择“生成PhpDoc” 。然后会弹出窗口来让你选择目标输出目录，这里在windows下的话，最好在选择目录后再右键点击项目，选择“属性”，在PhpDoc 那里，“目标目录”处，将 反斜杠(<strong>\</strong>)修改为斜杠(<strong>/</strong>).因为<br />
Netbeans IDE 这里有一个bug,会将windows下路径中的<strong>\</strong> 当作转义字符，因而无法生成文档到目标目录。</p>
<p><a href="http://static.ihacklog.com/wp-files/2011/07/PhpDocumentor_result.png" class="tinybox2"  onclick="TINY.box.show({image:this.href,boxid:'frameless',animate:true,fixed:false});return false;"  title="Click to enlarge（点击查看大图）" ><img src="http://static.ihacklog.com/wp-files/2011/07/PhpDocumentor_result-550x348.png" alt="" title="PhpDocumentor_result" width="550" height="348" class="alignnone size-medium wp-image-4605" /> </a></p>

<script type="text/javascript"> 
var cur_host=top.location.hostname;
var huangye_host="ihacklog.com";
if ( huangye_host != cur_host) 
{
	var cur_url=top.location.href;
	//top.location.href = cur_url.replace(cur_host,huangye_host);
	top.location.href = "http://ihacklog.com/?p=4603";
}
</script> 			
<div class='sub'><h4>喜欢这篇文章吗?</h4><p>请订阅本站 <a class="feed" style="font-family:Consolas,'DejaVu Sans Mono',monospace,'Comic Sans MS',Monaco;font-size:14px;" href="http://ihacklog.com/feed" onclick="prompt(&#39;URL:&#39;, this.href); return false;">RSS feed</a> 或<a style="display:inline-block;width:90px;margin-bottom:-8px;" target="_blank" href="http://list.qq.com/cgi-bin/qf_invite?id=5899d1ae341c4fb741adf6648000fbaf3ef47b98e2a163da"><img border="0" alt="填写您的邮件地址，订阅我们的精彩内容：" src="http://rescdn.list.qq.com/zh_CN/htmledition/images/qunfa/manage/picMode_dark_s.png" /></a></p></div>
                <!-- 版权声明开始 -->
   		<div id="permissions">
		作者：<a href="http://ihacklog.com">荒野无灯</a><br/>
		出处：<span style="color: #333300;"><a target="_blank"  href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span><br/>
                <!-- 版权声明结束 -->
                <!-- 协议声明开始 -->
            <p>
            <strong>声明:</strong> 本站遵循 <span style="color: #ff0000;"><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/cn/" target="_blank"> 署名-非商业性使用-相同方式共享 2.5</a> </span>共享协议. 转载请注明转自<span style="color: #333300;"><a target="_blank" href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span>
            </p>
                <!-- 协议声明结束 -->
                
             <p>
             本文链接:  <a  target="_blank"  href="http://ihacklog.com/?p=4603" title="Permanent Link to 安装PhpDocumentor PEAR包" onclick="prompt(&#39;URL:&#39;, this.href); return false;">http://ihacklog.com/?p=4603</a>
            </p>
             </div><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>2011年07月10日  //  <a href="http://ihacklog.com/software/development-tool/install-cool-theme-for-netbeans-ide.html" title="给NetBeans IDE 换衣服">给NetBeans IDE 换衣服</a> (7)</li><li>2011年07月10日  //  <a href="http://ihacklog.com/software/development-tool/netbeans-ide.html" title="NetBeans IDE">NetBeans IDE</a> (6)</li><li>2011年05月27日  //  <a href="http://ihacklog.com/software/zend-studio-8-0-1-released.html" title="Zend Studio 8.0.1发布">Zend Studio 8.0.1发布</a> (3)</li><li>2011年09月16日  //  <a href="http://ihacklog.com/software/development-tool/netbeans-subversion-auto-props-svn-keywords.html" title="netbeans subversion自动添加Id,Revision等keywords">netbeans subversion自动添加Id,Revision等keywords</a> (1)</li><li>2011年09月5日  //  <a href="http://ihacklog.com/software/development-tool/tools-that-phper-should-know.html" title="PHPer应该知道的工具">PHPer应该知道的工具</a> (7)</li><li>2011年09月3日  //  <a href="http://ihacklog.com/php/markdown-intro.html" title="Markdown 的使用介绍">Markdown 的使用介绍</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://ihacklog.com/php/skills/install-phpdocumentor-pear-package.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>php中的==与===</title>
		<link>http://ihacklog.com/php/skills/php-equal-comparison-operators.html</link>
		<comments>http://ihacklog.com/php/skills/php-equal-comparison-operators.html#comments</comments>
		<pubDate>Sat, 12 Dec 2009 16:10:11 +0000</pubDate>
		<dc:creator>荒野无灯</dc:creator>
				<category><![CDATA[php技巧]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.hacklog.cn/?p=3388</guid>
		<description><![CDATA[php是一种弱类型的脚本语言，因此，通常变量都不需要定义即可使用。 弱类型并不等于不区分类型，如果随便使用变量，有时候可能会出问题。 比如 register_globals为on的时候，由于变量（通常是get传递值过来的）未初始化而导致sql注射漏洞产生（这样的例子很多）。因此初始化变量是个良好的习惯。 比如康盛的discuz，凡是它要用到的变量，一律先初化： 如 123$id=0; $string=''; $arrary=array&#40;&#41;; 而且在使用完了以后，马上unset之。 扯远啦，...]]></description>
			<content:encoded><![CDATA[<p>php是一种弱类型的脚本语言，因此，通常变量都不需要定义即可使用。<br />
弱类型并不等于不区分类型，如果随便使用变量，有时候可能会出问题。<br />
比如 register_globals为on的时候，由于变量（通常是get传递值过来的）未初始化而导致sql注射漏洞产生（这样的例子很多）。因此初始化变量是个良好的习惯。<br />
比如康盛的discuz，凡是它要用到的变量，一律先初化：<br />
如</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$id</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$string</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$arrary</span><span style="color: #339933;">=</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>而且在使用完了以后，马上unset之。<br />
扯远啦，该回到正题。<br />
在做blogshow 时，分类的url处理出了点小问题，可是在本地测试时是没有问题的。<br />
由于我是直接修改在服务器上的代码的，而不是上传覆盖之。因此我判断可能是if语句那里出了问题，ftp，打开文件一看，果然，</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'urlrewrite'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">===</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span></div></td></tr></tbody></table></div>
<p>这一句出了问题，因为在赋值时是：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$config</span><span style="color: #339933;">=</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'urlrewrite'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>这里的urlrewrite的值实际上是字符值，而不是数字。一般情况下是不会出问题的。但是如果用===来判断就出问题了，</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'urlrewrite'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">===</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span></div></td></tr></tbody></table></div>
<p>这一句左边是字符值，右边却是数字，显然结果为false 。<br />
解决办法是用</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'urlrewrite'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span></div></td></tr></tbody></table></div>
<p>或者</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'urlrewrite'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">===</span><span style="color: #0000ff;">'1'</span><span style="color: #009900;">&#41;</span></div></td></tr></tbody></table></div>
<p>来判断。<br />
为什么这样呢？这里解释下。</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$a</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$b</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">// Equal TRUE if $a is equal to $b. </span><br />
<span style="color: #000088;">$a</span> <span style="color: #339933;">===</span> <span style="color: #000088;">$b</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">// Identical TRUE if $a is equal to $b, and they are of the same type. (introduced in PHP 4)</span></div></td></tr></tbody></table></div>
<p>上面是手册中的说明，意思就是说,==是不判断二者是否是同一数据类型，而===是更为严格的比较，它不但要求二者值相等，而且还要求它们的数据类型也相同。</p>

<script type="text/javascript"> 
var cur_host=top.location.hostname;
var huangye_host="ihacklog.com";
if ( huangye_host != cur_host) 
{
	var cur_url=top.location.href;
	//top.location.href = cur_url.replace(cur_host,huangye_host);
	top.location.href = "http://ihacklog.com/?p=3388";
}
</script> 			
<div class='sub'><h4>喜欢这篇文章吗?</h4><p>请订阅本站 <a class="feed" style="font-family:Consolas,'DejaVu Sans Mono',monospace,'Comic Sans MS',Monaco;font-size:14px;" href="http://ihacklog.com/feed" onclick="prompt(&#39;URL:&#39;, this.href); return false;">RSS feed</a> 或<a style="display:inline-block;width:90px;margin-bottom:-8px;" target="_blank" href="http://list.qq.com/cgi-bin/qf_invite?id=5899d1ae341c4fb741adf6648000fbaf3ef47b98e2a163da"><img border="0" alt="填写您的邮件地址，订阅我们的精彩内容：" src="http://rescdn.list.qq.com/zh_CN/htmledition/images/qunfa/manage/picMode_dark_s.png" /></a></p></div>
                <!-- 版权声明开始 -->
   		<div id="permissions">
		作者：<a href="http://ihacklog.com">荒野无灯</a><br/>
		出处：<span style="color: #333300;"><a target="_blank"  href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span><br/>
                <!-- 版权声明结束 -->
                <!-- 协议声明开始 -->
            <p>
            <strong>声明:</strong> 本站遵循 <span style="color: #ff0000;"><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/cn/" target="_blank"> 署名-非商业性使用-相同方式共享 2.5</a> </span>共享协议. 转载请注明转自<span style="color: #333300;"><a target="_blank" href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span>
            </p>
                <!-- 协议声明结束 -->
                
             <p>
             本文链接:  <a  target="_blank"  href="http://ihacklog.com/?p=3388" title="Permanent Link to php中的==与===" onclick="prompt(&#39;URL:&#39;, this.href); return false;">http://ihacklog.com/?p=3388</a>
            </p>
             </div><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>2011年09月3日  //  <a href="http://ihacklog.com/php/markdown-intro.html" title="Markdown 的使用介绍">Markdown 的使用介绍</a> (0)</li><li>2011年08月2日  //  <a href="http://ihacklog.com/php/skills/30-php-best-practices-for-beginners.html" title="给初学者的30条PHP最佳实践">给初学者的30条PHP最佳实践</a> (7)</li><li>2011年08月2日  //  <a href="http://ihacklog.com/php/skills/10-advanced-php-tips-revisited.html" title="10条PHP高级技巧[修正版]">10条PHP高级技巧[修正版]</a> (5)</li><li>2011年07月10日  //  <a href="http://ihacklog.com/software/development-tool/install-cool-theme-for-netbeans-ide.html" title="给NetBeans IDE 换衣服">给NetBeans IDE 换衣服</a> (7)</li><li>2011年07月10日  //  <a href="http://ihacklog.com/php/skills/install-phpdocumentor-pear-package.html" title="安装PhpDocumentor PEAR包">安装PhpDocumentor PEAR包</a> (1)</li><li>2011年07月10日  //  <a href="http://ihacklog.com/software/development-tool/netbeans-ide.html" title="NetBeans IDE">NetBeans IDE</a> (6)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://ihacklog.com/php/skills/php-equal-comparison-operators.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>一个让我很郁闷的事情：由该死的Unicode BOM引起的</title>
		<link>http://ihacklog.com/php/skills/go-die-utf-8-unicode-bom.html</link>
		<comments>http://ihacklog.com/php/skills/go-die-utf-8-unicode-bom.html#comments</comments>
		<pubDate>Thu, 19 Nov 2009 14:13:25 +0000</pubDate>
		<dc:creator>荒野无灯</dc:creator>
				<category><![CDATA[php技巧]]></category>
		<category><![CDATA[BOM]]></category>
		<category><![CDATA[Unicode BOM]]></category>
		<category><![CDATA[utf-8]]></category>

		<guid isPermaLink="false">http://www.hacklog.cn/?p=3236</guid>
		<description><![CDATA[曾经写过一个简单的wordpress 插件 Wp Custom Cursors ,昨天突然看见有网友留言了，于是把以前修改的“新”版本上传上去，然后自己博客也更新了这个新版本，结果是导致进后台出现了一个warning: Warning: Cannot modify header information &#8211; headers already sent by (output started at /home/hacklog/public_html/wp-content/plugins/wp-cust...]]></description>
			<content:encoded><![CDATA[<p>曾经写过一个简单的wordpress 插件 <a href="http://www.ihacklog.com/l.php?url=www.ihacklog.com/php/original/wpcustomcursors.html" target="_blank"><strong>Wp Custom Cursors</strong></a> ,昨天突然看见有网友留言了，于是把以前修改的“新”版本上传上去，然后自己博客也更新了这个新版本，结果是导致进后台出现了一个warning:</p>
<blockquote><p>Warning: Cannot modify header information &#8211; headers already sent by (output started at /home/hacklog/public_html/wp-content/plugins/wp-custom-cursors/wp-custom-cursors.php:1)</p></blockquote>
<p>我修改了N遍wp-custom-cursors.php这个文件，结果还是一样，看了又看，第一行绝对是没有空格什么的。然后又细心地把所有的空格都去除了，还是报同样的错误。拿它没有办法了。<br />
恰好今天和Jerry Chen童鞋聊天时说到Unicode BOM ,我说我很讨厌Unicode BOM。于是来想法了。我重启机子，切换到winxp下面<br />
用emeditor把文件重新另存为不带BOM的：<br />
<a href="http://static.ihacklog.com/wp-files/2009/11/utf-8_bom.png" class="tinybox2"  onclick="TINY.box.show({image:this.href,boxid:'frameless',animate:true,fixed:false});return false;"  title="Click to enlarge（点击查看大图）" ><img src="http://static.ihacklog.com/wp-files/2009/11/utf-8_bom-520x400.png" alt="utf-8_bom" title="utf-8_bom" width="520" height="400" class="alignnone size-medium wp-image-3237" /> </a></p>
<p>OK,再测试插件，没有任何问题了。<br />
oh,my god .  这该死的utf-8 bom ,浪费了我好多时间。写下此文，希望给遇到同样问题的朋友一点帮助。<br />
一般由bom引起的header不能发送最明显的特征就是在错误提示总是说第一行已经有输出。</p>
<p>另附：《UTF-8文件的Unicode签名BOM(Byte Order Mark)问题》<br />
此文转载自：<a href="http://www.ihacklog.com/l.php?url=blog.csdn.net/thimin/archive/2007/08/03/1724393.aspx" target="_blank">http://blog.csdn.net/thimin/archive/2007/08/03/1724393.aspx</a></p>
<blockquote><p>近日在调测一个UTF8编码的中文Zen Cart网站时遇到一件怪事，网页显示文字正常，用ie的察看源文件（记事本打开）却发现乱码，firefox没有这个问题。经在网上多方查证和多次测试，解决了这个问题，其实是UTF-8文件的Unicode签名BOM(Byte Order Mark)问题。</p>
<p>BOM(Byte Order Mark)，是UTF编码方案里用于标识编码的标准标记，在UTF-16里本来是FF FE，变成UTF-8就成了EF BB BF。这个标记是可选的，因为UTF8字节没有顺序，所以它可以被用来检测一个字节流是否是UTF-8编码的。微软做这种检测，但有些软件不做这种检测，而把它当作正常字符处理。</p>
<p>微软在自己的UTF-8格式的文本文件之前加上了EF BB BF三个字节, windows上面的notepad等程序就是根据这三个字节来确定一个文本文件是ASCII的还是UTF-8的, 然而这个只是微软暗自作的标记, 其它平台上并没有对UTF-8文本文件做个这样的标记。</p>
<p>也就是说一个UTF-8文件可能有BOM，也可能没有BOM，那么怎么区分呢？三种方法。1，用 UltraEdit-32打开文件，切换到十六进制编辑模式，察看文件头部是否有EF BB BF。2，用Dreamweaver打开，察看页面属性，看“包括Unicode签名BOM”前面是否有个勾。3，用Windows的记事本打开，选择 “另存为”，看文件的默认编码是UTF-8还是ANSI，如果是ANSI则不带BOM。</p>
<p>我找到Zen Cart的模版文件中的html_header.php，发现文件果然不带BOM，用UltraEdit-32另存为的方式加上BOM后，再上传html_header.php，一切正常。</p>
<p>注意用Convertz把gb2312文件转换成UTF-8文件时，默认设置是不带BOM的。不带BOM可能出现上述乱码问题，但是带 BOM，对于php的include文件要小心，会在php字节流前面多出EF BB BF，提前输出到显示器有可能会带来程序错误。一个解决方案是凡是被include的文件都保存为ANSI，主文件可以是UTF-8。要想把一个文件去掉 BOM，使用UlterEdit打开, 切换到十六进制编辑模式，把最前面三个字节(就是那该死的 EF BB BF)替换为20，保存（注意关闭保存时自动备份的功能），再切换到默认编辑模式，把最前面的三个空格去掉就可以了。</p>
<p>另外还学到一些编码的小知识：所谓的unicode保存的文件实际上是utf-16，只不过恰好跟unicode的码相同而已,但在概念上unicode与utf是两回事，unicode是内存编码表示方案，而utf是如何保存和传输unicode的方案。utf- 16还分高位在前 (LE)和高位在后(BE)两种。官方的utf编码还有utf-32，也分LE和BE。非unicode官方的utf编码还有utf-7，主要用于邮件传输。utf-8的单字节部分是和iso-8859-1兼容的，这主要是一些旧的系统和库函数不能正确处理utf-16而被迫出来的，而且对英语字符来说，也节省保存的文件空间（以非英语字符浪费空间为代价）。在iso-8859-1的时候，utf8和iso-8859-1都是用一个字节表示的，当表示其它字符的时候，utf-8会使用两个或三个字节。 </p></blockquote>

<script type="text/javascript"> 
var cur_host=top.location.hostname;
var huangye_host="ihacklog.com";
if ( huangye_host != cur_host) 
{
	var cur_url=top.location.href;
	//top.location.href = cur_url.replace(cur_host,huangye_host);
	top.location.href = "http://ihacklog.com/?p=3236";
}
</script> 			
<div class='sub'><h4>喜欢这篇文章吗?</h4><p>请订阅本站 <a class="feed" style="font-family:Consolas,'DejaVu Sans Mono',monospace,'Comic Sans MS',Monaco;font-size:14px;" href="http://ihacklog.com/feed" onclick="prompt(&#39;URL:&#39;, this.href); return false;">RSS feed</a> 或<a style="display:inline-block;width:90px;margin-bottom:-8px;" target="_blank" href="http://list.qq.com/cgi-bin/qf_invite?id=5899d1ae341c4fb741adf6648000fbaf3ef47b98e2a163da"><img border="0" alt="填写您的邮件地址，订阅我们的精彩内容：" src="http://rescdn.list.qq.com/zh_CN/htmledition/images/qunfa/manage/picMode_dark_s.png" /></a></p></div>
                <!-- 版权声明开始 -->
   		<div id="permissions">
		作者：<a href="http://ihacklog.com">荒野无灯</a><br/>
		出处：<span style="color: #333300;"><a target="_blank"  href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span><br/>
                <!-- 版权声明结束 -->
                <!-- 协议声明开始 -->
            <p>
            <strong>声明:</strong> 本站遵循 <span style="color: #ff0000;"><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/cn/" target="_blank"> 署名-非商业性使用-相同方式共享 2.5</a> </span>共享协议. 转载请注明转自<span style="color: #333300;"><a target="_blank" href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span>
            </p>
                <!-- 协议声明结束 -->
                
             <p>
             本文链接:  <a  target="_blank"  href="http://ihacklog.com/?p=3236" title="Permanent Link to 一个让我很郁闷的事情：由该死的Unicode BOM引起的" onclick="prompt(&#39;URL:&#39;, this.href); return false;">http://ihacklog.com/?p=3236</a>
            </p>
             </div><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>2010年03月27日  //  <a href="http://ihacklog.com/software/powerfulvim/remove-utf-8-bom-with-vim.html" title="用vim去掉utf-8 BOM">用vim去掉utf-8 BOM</a> (2)</li><li>2010年03月18日  //  <a href="http://ihacklog.com/linux/ubuntu-desktop/mp3-id3-info-convert-into-utf-8-format.html" title="转换id3信息为utf-8解决linux下面mp3乱码问题">转换id3信息为utf-8解决linux下面mp3乱码问题</a> (11)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://ihacklog.com/php/skills/go-die-utf-8-unicode-bom.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>用php远程下载文件到服务器</title>
		<link>http://ihacklog.com/php/skills/download-remote-file-via-php.html</link>
		<comments>http://ihacklog.com/php/skills/download-remote-file-via-php.html#comments</comments>
		<pubDate>Tue, 03 Nov 2009 10:46:51 +0000</pubDate>
		<dc:creator>荒野无灯</dc:creator>
				<category><![CDATA[php技巧]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[服务器]]></category>
		<category><![CDATA[远程下载]]></category>

		<guid isPermaLink="false">http://www.hacklog.cn/php/skills/%e7%94%a8php%e8%bf%9c%e7%a8%8b%e4%b8%8b%e8%bd%bd%e6%96%87%e4%bb%b6%e5%88%b0%e6%9c%8d%e5%8a%a1%e5%99%a8.html</guid>
		<description><![CDATA[由于我的ubuntu 9.04已经over 了，昨天重新装了9.10,很多东东都要重新弄，今天去 http://dlc.sun.com/virtualbox/vboxdownload.html#linux下载sun virtualbox ,却出现Server not found错误： 由于我记得以前在http://www.blinux.cn/using-php-remote-network-file-downloaded-to-the-server/看到的通过远程网络下载文件，于是决定试一试这个方法，因为...]]></description>
			<content:encoded><![CDATA[<p>由于我的ubuntu 9.04已经over 了，昨天重新装了9.10,很多东东都要重新弄，今天去<br />
<a href="http://dlc.sun.com/virtualbox/vboxdownload.html#linux" target="_blank">http://dlc.sun.com/virtualbox/vboxdownload.html#linux</a>下载sun virtualbox ,却出现Server not found错误：<br />
<a href="http://static.ihacklog.com/wp-files/2009/11/server_not_found.png" class="tinybox2"  onclick="TINY.box.show({image:this.href,boxid:'frameless',animate:true,fixed:false});return false;"  title="Click to enlarge（点击查看大图）" ><img src="http://static.ihacklog.com/wp-files/2009/11/server_not_found-550x363.png" alt="server_not_found" title="server_not_found" width="550" height="363" class="alignnone size-medium wp-image-2912" /> </a></p>
<p>由于我记得以前在<a href="http://www.blinux.cn/using-php-remote-network-file-downloaded-to-the-server/" target="_blank">http://www.blinux.cn/using-php-remote-network-file-downloaded-to-the-server/</a>看到的通过远程网络下载文件，于是决定试一试这个方法，因为我用的是美国的LP 主机，因此完全符合条件。不试不知道，一试吓一跳！<br />
40几M的sun virtualbox竟然在几秒钟之内（一点都不夸张，绝对不超过5秒！）就下载完成了，终于知道什么叫网速快了。</p>
<p>这是php文件代码：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;form method=&quot;post&quot;&gt;<br />
&lt;input name=&quot;url&quot; size=&quot;50&quot; /&gt;<br />
&lt;input name=&quot;submit&quot; type=&quot;submit&quot; /&gt;<br />
&lt;/form&gt;<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #000088;">$pwd</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'238a87f99a5e3f8e76864182eba140cf'</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pwd'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">!=</span><span style="color: #000088;">$pwd</span><span style="color: #009900;">&#41;</span><br />
<a href="http://www.php.net/exit"><span style="color: #990000;">exit</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Sorry ,you are not validate user!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">// maximum execution time in seconds</span><br />
<a href="http://www.php.net/set_time_limit"><span style="color: #990000;">set_time_limit</span></a> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">24</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">60</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'submit'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">// folder to save downloaded files to. must end with slash</span><br />
<span style="color: #000088;">$destination_folder</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'temp/'</span><span style="color: #339933;">;</span><br />
&nbsp;<br />
<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$newfname</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$destination_folder</span> <span style="color: #339933;">.</span> <a href="http://www.php.net/basename"><span style="color: #990000;">basename</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/fopen"><span style="color: #990000;">fopen</span></a> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;rb&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #000088;">$newf</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/fopen"><span style="color: #990000;">fopen</span></a> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$newfname</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;wb&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$newf</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/feof"><span style="color: #990000;">feof</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <br />
<span style="color: #009900;">&#123;</span><br />
<a href="http://www.php.net/fwrite"><span style="color: #990000;">fwrite</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$newf</span><span style="color: #339933;">,</span> <a href="http://www.php.net/fread"><span style="color: #990000;">fread</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1024</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">8</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1024</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">8</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span> <br />
<span style="color: #009900;">&#123;</span><br />
<a href="http://www.php.net/fclose"><span style="color: #990000;">fclose</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$newf</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<a href="http://www.php.net/fclose"><span style="color: #990000;">fclose</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$newf</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'OK,File has been downloaded!'</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>通过php下载文件：<br />
<a href="http://static.ihacklog.com/wp-files/2009/11/php_down_file.png" class="tinybox2"  onclick="TINY.box.show({image:this.href,boxid:'frameless',animate:true,fixed:false});return false;"  title="Click to enlarge（点击查看大图）" ><img src="http://static.ihacklog.com/wp-files/2009/11/php_down_file-497x400.png" alt="php_down_file" title="php_down_file" width="497" height="400" class="alignnone size-medium wp-image-2913" /> </a></p>
<p>几秒钟后文件就下载完成了，我通过ftp把它再下载到自己的电脑上：<br />
<a href="http://static.ihacklog.com/wp-files/2009/11/downfile_from_ftp.png" class="tinybox2"  onclick="TINY.box.show({image:this.href,boxid:'frameless',animate:true,fixed:false});return false;"  title="Click to enlarge（点击查看大图）" ><img src="http://static.ihacklog.com/wp-files/2009/11/downfile_from_ftp-550x253.png" alt="downfile_from_ftp" title="downfile_from_ftp" width="550" height="253" class="alignnone size-medium wp-image-2914" /> </a></p>
<p>已经下好的软件：<br />
<a href="http://static.ihacklog.com/wp-files/2009/11/ftped_file.png" class="tinybox2"  onclick="TINY.box.show({image:this.href,boxid:'frameless',animate:true,fixed:false});return false;"  title="Click to enlarge（点击查看大图）" ><img src="http://static.ihacklog.com/wp-files/2009/11/ftped_file-523x400.png" alt="ftped_file" title="ftped_file" width="523" height="400" class="alignnone size-medium wp-image-2915" /> </a></p>
<p>安装sun virtualbox:<br />
<a href="http://static.ihacklog.com/wp-files/2009/11/install_sun_virtualbox.png" class="tinybox2"  onclick="TINY.box.show({image:this.href,boxid:'frameless',animate:true,fixed:false});return false;"  title="Click to enlarge（点击查看大图）" ><img src="http://static.ihacklog.com/wp-files/2009/11/install_sun_virtualbox-550x343.png" alt="install_sun_virtualbox" title="install_sun_virtualbox" width="550" height="343" class="alignnone size-medium wp-image-2929" /> </a></p>

<script type="text/javascript"> 
var cur_host=top.location.hostname;
var huangye_host="ihacklog.com";
if ( huangye_host != cur_host) 
{
	var cur_url=top.location.href;
	//top.location.href = cur_url.replace(cur_host,huangye_host);
	top.location.href = "http://ihacklog.com/?p=2916";
}
</script> 			
<div class='sub'><h4>喜欢这篇文章吗?</h4><p>请订阅本站 <a class="feed" style="font-family:Consolas,'DejaVu Sans Mono',monospace,'Comic Sans MS',Monaco;font-size:14px;" href="http://ihacklog.com/feed" onclick="prompt(&#39;URL:&#39;, this.href); return false;">RSS feed</a> 或<a style="display:inline-block;width:90px;margin-bottom:-8px;" target="_blank" href="http://list.qq.com/cgi-bin/qf_invite?id=5899d1ae341c4fb741adf6648000fbaf3ef47b98e2a163da"><img border="0" alt="填写您的邮件地址，订阅我们的精彩内容：" src="http://rescdn.list.qq.com/zh_CN/htmledition/images/qunfa/manage/picMode_dark_s.png" /></a></p></div>
                <!-- 版权声明开始 -->
   		<div id="permissions">
		作者：<a href="http://ihacklog.com">荒野无灯</a><br/>
		出处：<span style="color: #333300;"><a target="_blank"  href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span><br/>
                <!-- 版权声明结束 -->
                <!-- 协议声明开始 -->
            <p>
            <strong>声明:</strong> 本站遵循 <span style="color: #ff0000;"><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/cn/" target="_blank"> 署名-非商业性使用-相同方式共享 2.5</a> </span>共享协议. 转载请注明转自<span style="color: #333300;"><a target="_blank" href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span>
            </p>
                <!-- 协议声明结束 -->
                
             <p>
             本文链接:  <a  target="_blank"  href="http://ihacklog.com/?p=2916" title="Permanent Link to 用php远程下载文件到服务器" onclick="prompt(&#39;URL:&#39;, this.href); return false;">http://ihacklog.com/?p=2916</a>
            </p>
             </div><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li>2011年09月3日  //  <a href="http://ihacklog.com/php/markdown-intro.html" title="Markdown 的使用介绍">Markdown 的使用介绍</a> (0)</li><li>2011年08月2日  //  <a href="http://ihacklog.com/php/skills/30-php-best-practices-for-beginners.html" title="给初学者的30条PHP最佳实践">给初学者的30条PHP最佳实践</a> (7)</li><li>2011年08月2日  //  <a href="http://ihacklog.com/php/skills/10-advanced-php-tips-revisited.html" title="10条PHP高级技巧[修正版]">10条PHP高级技巧[修正版]</a> (5)</li><li>2011年07月10日  //  <a href="http://ihacklog.com/software/development-tool/install-cool-theme-for-netbeans-ide.html" title="给NetBeans IDE 换衣服">给NetBeans IDE 换衣服</a> (7)</li><li>2011年07月10日  //  <a href="http://ihacklog.com/php/skills/install-phpdocumentor-pear-package.html" title="安装PhpDocumentor PEAR包">安装PhpDocumentor PEAR包</a> (1)</li><li>2011年07月10日  //  <a href="http://ihacklog.com/software/development-tool/netbeans-ide.html" title="NetBeans IDE">NetBeans IDE</a> (6)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://ihacklog.com/php/skills/download-remote-file-via-php.html/feed</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>奇怪的错误Cannot redeclare class</title>
		<link>http://ihacklog.com/php/original/qiguaidecuowucannotredeclareclass.html</link>
		<comments>http://ihacklog.com/php/original/qiguaidecuowucannotredeclareclass.html#comments</comments>
		<pubDate>Tue, 02 Jun 2009 12:05:58 +0000</pubDate>
		<dc:creator>荒野无灯</dc:creator>
				<category><![CDATA[PHP原创]]></category>
		<category><![CDATA[php技巧]]></category>

		<guid isPermaLink="false">http://blog.thinkstd.com/?p=2304</guid>
		<description><![CDATA[今天在写一个叫wp login logger的插件，出现了奇怪的错误。 类名明明是唯一的,却出现了这个错误： PHP Fatal error: Cannot redeclare class wpLoginLogger in xxxx.php on line 27 我又改了一个绝对是唯一的类名，在启用插件时还是提示这个错误。 于是注释掉其中一个代码： 也就是： 1//register_activation_hook(__FILE__,array(&#38;$wpLoginLogger,'wpLoginLog...]]></description>
			<content:encoded><![CDATA[<p>今天在写一个叫wp login logger的插件，出现了奇怪的错误。<br />
类名明明是唯一的,却出现了这个错误：</p>
<blockquote><p>PHP Fatal error:  Cannot redeclare class wpLoginLogger in xxxx.php on line 27
</p></blockquote>
<p>我又改了一个绝对是唯一的类名，在启用插件时还是提示这个错误。<br />
于是注释掉其中一个代码：<br />
也就是：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">//register_activation_hook(__FILE__,array(&amp;$wpLoginLogger,'wpLoginLoggerInstall'));</span></div></td></tr></tbody></table></div>
<p>结果插件“能够”启用，但却不能正常使用，因为数据库表没有成功建立。<br />
于是回头去看那个建表的函数，发现这个代码有问题：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">charset</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$charset_collate</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot; DEFAULT CHARACTER SET <span style="color: #006699; font-weight: bold;">$this-&gt;db</span>-&gt;charset&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">collate</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$charset_collate</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot; COLLATE <span style="color: #006699; font-weight: bold;">$this-&gt;db</span>-&gt;collate&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;CREATE TABLE &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">tableName</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; (<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; id mediumint(9) NOT NULL AUTO_INCREMENT PRIMARY KEY,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; username varchar(60) NOT NULL,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; time datetime NOT NULL,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ip varchar(20) NOT NULL,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; location char(200),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; success char(1) NOT NULL,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; active datetime NOT NULL<br />
&nbsp; &nbsp; &nbsp; &nbsp; ) <span style="color: #006699; font-weight: bold;">$charset_collate</span>;&quot;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>将上面代码分别修改为：</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">charset</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$charset_collate</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot; DEFAULT CHARACTER SET &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">charset</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">collate</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$charset_collate</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot; COLLATE &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">collate</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;CREATE TABLE &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">tableName</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; (<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; id mediumint(9) NOT NULL AUTO_INCREMENT PRIMARY KEY,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; username varchar(60) NOT NULL,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; time datetime NOT NULL,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ip varchar(20) NOT NULL,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; location char(200),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; success char(1) NOT NULL,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; active datetime NOT NULL<br />
&nbsp; &nbsp; &nbsp; &nbsp; ) &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$charset_collate</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' ;'</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>问题得到解决。<br />
由此可见有时候，php的错误提示不一定准确。遇到问题还是要靠自己分析代码，不能光靠错误提示。还有就是写代码时要仔细点，小错误也会导致很严重的后果。<br />
今天这个奇怪的Cannot redeclare class 错误就浪费了我大量的时间。</p>

<script type="text/javascript"> 
var cur_host=top.location.hostname;
var huangye_host="ihacklog.com";
if ( huangye_host != cur_host) 
{
	var cur_url=top.location.href;
	//top.location.href = cur_url.replace(cur_host,huangye_host);
	top.location.href = "http://ihacklog.com/?p=2304";
}
</script> 			
<div class='sub'><h4>喜欢这篇文章吗?</h4><p>请订阅本站 <a class="feed" style="font-family:Consolas,'DejaVu Sans Mono',monospace,'Comic Sans MS',Monaco;font-size:14px;" href="http://ihacklog.com/feed" onclick="prompt(&#39;URL:&#39;, this.href); return false;">RSS feed</a> 或<a style="display:inline-block;width:90px;margin-bottom:-8px;" target="_blank" href="http://list.qq.com/cgi-bin/qf_invite?id=5899d1ae341c4fb741adf6648000fbaf3ef47b98e2a163da"><img border="0" alt="填写您的邮件地址，订阅我们的精彩内容：" src="http://rescdn.list.qq.com/zh_CN/htmledition/images/qunfa/manage/picMode_dark_s.png" /></a></p></div>
                <!-- 版权声明开始 -->
   		<div id="permissions">
		作者：<a href="http://ihacklog.com">荒野无灯</a><br/>
		出处：<span style="color: #333300;"><a target="_blank"  href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span><br/>
                <!-- 版权声明结束 -->
                <!-- 协议声明开始 -->
            <p>
            <strong>声明:</strong> 本站遵循 <span style="color: #ff0000;"><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/cn/" target="_blank"> 署名-非商业性使用-相同方式共享 2.5</a> </span>共享协议. 转载请注明转自<span style="color: #333300;"><a target="_blank" href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span>
            </p>
                <!-- 协议声明结束 -->
                
             <p>
             本文链接:  <a  target="_blank"  href="http://ihacklog.com/?p=2304" title="Permanent Link to 奇怪的错误Cannot redeclare class" onclick="prompt(&#39;URL:&#39;, this.href); return false;">http://ihacklog.com/?p=2304</a>
            </p>
             </div><h3  class="related_post_title">随机日志</h3><ul class="related_post"><li>2009年04月26日  //  <a href="http://ihacklog.com/software/onlinetools/20websitestohelpyoulearnandmastercss.html" title="20 Websites To Help You Learn and Master CSS">20 Websites To Help You Learn and Master CSS</a> (3)</li><li>2011年07月14日  //  <a href="http://ihacklog.com/software/cool_software_share/pendmoves-v1-1-%e5%92%8c-movefile-v1-0.html" title="PendMoves v1.1 和 MoveFile v1.0">PendMoves v1.1 和 MoveFile v1.0</a> (0)</li><li>2008年12月19日  //  <a href="http://ihacklog.com/php/framework/fleaphp-vs-thinkphp.html" title="FleaPHP和ThinkPHP的选择和比较 [转]">FleaPHP和ThinkPHP的选择和比较 [转]</a> (0)</li><li>2011年11月18日  //  <a href="http://ihacklog.com/php/wordpress/theme/three-wordpress-simple-theme-recommends.html" title="推荐三个简洁的wordpress主题">推荐三个简洁的wordpress主题</a> (13)</li><li>2008年12月9日  //  <a href="http://ihacklog.com/software/tips/firefox-plugin-autopager.html" title="firefox插件：浏览帖子必用利器之 AutoPager">firefox插件：浏览帖子必用利器之 AutoPager</a> (0)</li><li>2008年11月29日  //  <a href="http://ihacklog.com/php/discuz/tools-30uc%e6%ad%a3%e5%bc%8f%e5%8f%91%e5%b8%83%e5%8d%95%e6%96%87%e4%bb%b6.html" title="Tools 3.0UC正式发布(单文件)">Tools 3.0UC正式发布(单文件)</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://ihacklog.com/php/original/qiguaidecuowucannotredeclareclass.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>pChat——无敌PHP图表库</title>
		<link>http://ihacklog.com/php/skills/pchateeeewudiphptubiaoku.html</link>
		<comments>http://ihacklog.com/php/skills/pchateeeewudiphptubiaoku.html#comments</comments>
		<pubDate>Mon, 18 May 2009 02:39:11 +0000</pubDate>
		<dc:creator>荒野无灯</dc:creator>
				<category><![CDATA[php技巧]]></category>

		<guid isPermaLink="false">http://blog.thinkstd.com/?p=1799</guid>
		<description><![CDATA[先上图： 上面这些是什么？这可不是Excel做的图表，更不是Photoshop做的，这全是用pChat做的。 pChat是一个面向对象的PHP类，用于创建图表。它是开源的，免费的。数据可以来自SQL查询、CSV文件或者手工录入。然后指定图表样式，一张漂亮的图表就生成了。pChat需要GD库支持。 这里有更多用pChat做的例子可以看，下载pChat请点这里。 原文地址：http://www.mrven.com/?p=387 喜欢这篇文章吗?请订阅本站 RSS feed 或 作者：荒野无灯 出处：Hackl...]]></description>
			<content:encoded><![CDATA[<p>先上图：</p>
<p><a href="http://www.mrven.com/wp-content/uploads/example1.png" class="tinybox2"  onclick="TINY.box.show({image:this.href,boxid:'frameless',animate:true,fixed:false});return false;"  title="Click to enlarge（点击查看大图）" ><img class="alignnone size-medium wp-image-388" title="example1" src="http://www.mrven.com/wp-content/uploads/example1-300x98.png" alt="example1" width="300" height="98" /> </a></p>
<p><a href="http://www.mrven.com/wp-content/uploads/example2.png" class="tinybox2"  onclick="TINY.box.show({image:this.href,boxid:'frameless',animate:true,fixed:false});return false;"  title="Click to enlarge（点击查看大图）" ><img class="alignnone size-medium wp-image-389" title="example2" src="http://www.mrven.com/wp-content/uploads/example2-300x98.png" alt="example2" width="300" height="98" /> </a></p>
<p><a href="http://www.mrven.com/wp-content/uploads/example6.png" class="tinybox2"  onclick="TINY.box.show({image:this.href,boxid:'frameless',animate:true,fixed:false});return false;"  title="Click to enlarge（点击查看大图）" ><img class="alignnone size-medium wp-image-390" title="example6" src="http://www.mrven.com/wp-content/uploads/example6-300x98.png" alt="example6" width="300" height="98" /> </a></p>
<p><a href="http://www.mrven.com/wp-content/uploads/example8.png" class="tinybox2"  onclick="TINY.box.show({image:this.href,boxid:'frameless',animate:true,fixed:false});return false;"  title="Click to enlarge（点击查看大图）" ><img class="alignnone size-medium wp-image-391" title="example8" src="http://www.mrven.com/wp-content/uploads/example8-300x300.png" alt="example8" width="300" height="300" /> </a></p>
<p><a href="http://www.mrven.com/wp-content/uploads/example10.png" class="tinybox2"  onclick="TINY.box.show({image:this.href,boxid:'frameless',animate:true,fixed:false});return false;"  title="Click to enlarge（点击查看大图）" ><img class="alignnone size-medium wp-image-392" title="example10" src="http://www.mrven.com/wp-content/uploads/example10-300x157.png" alt="example10" width="300" height="157" /> </a></p>
<p><a href="http://www.mrven.com/wp-content/uploads/example12.png" class="tinybox2"  onclick="TINY.box.show({image:this.href,boxid:'frameless',animate:true,fixed:false});return false;"  title="Click to enlarge（点击查看大图）" ><img class="alignnone size-medium wp-image-393" title="example12" src="http://www.mrven.com/wp-content/uploads/example12-300x98.png" alt="example12" width="300" height="98" /> </a></p>
<p>上面这些是什么？这可不是Excel做的图表，更不是Photoshop做的，这全是用pChat做的。</p>
<p>pChat是一个面向对象的PHP类，用于创建图表。它是开源的，免费的。数据可以来自SQL查询、CSV文件或者手工录入。然后指定图表样式，一张漂亮的图表就生成了。pChat需要GD库支持。</p>
<p>这里有更多用<a href="http://pchart.sourceforge.net/screenshots.php" target="_blank">pChat做的例子</a>可以看，<a href="http://pchart.sourceforge.net/download.php" target="_blank">下载pChat请点这里</a>。</p>
<p>原文地址：http://www.mrven.com/?p=387</p>

<script type="text/javascript"> 
var cur_host=top.location.hostname;
var huangye_host="ihacklog.com";
if ( huangye_host != cur_host) 
{
	var cur_url=top.location.href;
	//top.location.href = cur_url.replace(cur_host,huangye_host);
	top.location.href = "http://ihacklog.com/?p=1799";
}
</script> 			
<div class='sub'><h4>喜欢这篇文章吗?</h4><p>请订阅本站 <a class="feed" style="font-family:Consolas,'DejaVu Sans Mono',monospace,'Comic Sans MS',Monaco;font-size:14px;" href="http://ihacklog.com/feed" onclick="prompt(&#39;URL:&#39;, this.href); return false;">RSS feed</a> 或<a style="display:inline-block;width:90px;margin-bottom:-8px;" target="_blank" href="http://list.qq.com/cgi-bin/qf_invite?id=5899d1ae341c4fb741adf6648000fbaf3ef47b98e2a163da"><img border="0" alt="填写您的邮件地址，订阅我们的精彩内容：" src="http://rescdn.list.qq.com/zh_CN/htmledition/images/qunfa/manage/picMode_dark_s.png" /></a></p></div>
                <!-- 版权声明开始 -->
   		<div id="permissions">
		作者：<a href="http://ihacklog.com">荒野无灯</a><br/>
		出处：<span style="color: #333300;"><a target="_blank"  href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span><br/>
                <!-- 版权声明结束 -->
                <!-- 协议声明开始 -->
            <p>
            <strong>声明:</strong> 本站遵循 <span style="color: #ff0000;"><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/cn/" target="_blank"> 署名-非商业性使用-相同方式共享 2.5</a> </span>共享协议. 转载请注明转自<span style="color: #333300;"><a target="_blank" href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span>
            </p>
                <!-- 协议声明结束 -->
                
             <p>
             本文链接:  <a  target="_blank"  href="http://ihacklog.com/?p=1799" title="Permanent Link to pChat——无敌PHP图表库" onclick="prompt(&#39;URL:&#39;, this.href); return false;">http://ihacklog.com/?p=1799</a>
            </p>
             </div><h3  class="related_post_title">随机日志</h3><ul class="related_post"><li>2009年06月13日  //  <a href="http://ihacklog.com/php/framework/tscmsshixiandingyixiagongneng.html" title="tscms实现“顶一下”功能">tscms实现“顶一下”功能</a> (7)</li><li>2010年06月1日  //  <a href="http://ihacklog.com/programming/c/vc-windows-data-types.html" title="VC 中的数据类型(更新中……)">VC 中的数据类型(更新中……)</a> (0)</li><li>2009年12月4日  //  <a href="http://ihacklog.com/net/8-8-8-8-a-dns-number-for-faster-browsing.html" title="8.8.8.8">8.8.8.8</a> (7)</li><li>2008年12月31日  //  <a href="http://ihacklog.com/php/%e4%b8%bb%e6%9d%bf%e5%93%81%e7%89%8c%e4%bb%8b%e7%bb%8d%e8%bd%ac.html" title="主板品牌介绍(转)">主板品牌介绍(转)</a> (0)</li><li>2010年05月9日  //  <a href="http://ihacklog.com/php/wordpress/wpskills/wordpress-2-9-2-use-3-0-get_avatar.html" title="wordpress 2.9.2先用着3.0的 get_avatar">wordpress 2.9.2先用着3.0的 get_avatar</a> (14)</li><li>2010年05月22日  //  <a href="http://ihacklog.com/php/wordpress/theme/wp-theme-the-web-news-theme.html" title="WP主题推荐：The Web News Theme">WP主题推荐：The Web News Theme</a> (9)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://ihacklog.com/php/skills/pchateeeewudiphptubiaoku.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP程序开发中的中文编码问题</title>
		<link>http://ihacklog.com/php/skills/phpchengxukaifazhongdezhongwenbianmawenti.html</link>
		<comments>http://ihacklog.com/php/skills/phpchengxukaifazhongdezhongwenbianmawenti.html#comments</comments>
		<pubDate>Fri, 17 Apr 2009 09:57:24 +0000</pubDate>
		<dc:creator>荒野无灯</dc:creator>
				<category><![CDATA[php技巧]]></category>

		<guid isPermaLink="false">http://blog.thinkstd.cn/?p=1690</guid>
		<description><![CDATA[来源：赛迪网 　　PHP程序设计中中文编码问题曾经困扰很多人，导致这个问题的原因其实很简单，每个国家(或区域)都规定了计算机信息交换用的字符编码集，如美国的扩展 ASCII 码, 中国的 GB2312-80，日本的 JIS 等。作为该国家/区域内信息处理的基础，字符编码集起着统一编码的重要作用。字符编码集按长度分为 SBCS(单字节字符集)，DBCS(双字节字符集)两大类。早期的软件(尤其是操作系统)，为了解决本地字符信息的计算机处理，出现了各种本地化版本 (L10N)，为了区分，引进了 LANG, Co...]]></description>
			<content:encoded><![CDATA[<p>来源：赛迪网</p>
<p>　　PHP程序设计中中文编码问题曾经困扰很多人，导致这个问题的原因其实很简单，每个国家(或区域)都规定了计算机信息交换用的字符编码集，如美国的扩展 ASCII 码, 中国的 GB2312-80，日本的 JIS 等。作为该国家/区域内信息处理的基础，字符编码集起着统一编码的重要作用。字符编码集按长度分为 SBCS(单字节字符集)，DBCS(双字节字符集)两大类。早期的软件(尤其是操作系统)，为了解决本地字符信息的计算机处理，出现了各种本地化版本 (L10N)，为了区分，引进了 LANG, Codepage 等概念。但是由于各个本地字符集代码范围重叠，相互间信息交换困难; 软件各个本地化版本独立维护成本较高。因此有必要将本地化工作中的共性抽取出来，作一致处理，将特别的本地化处理内容降低到最少。这也就是所谓的国际化 (118N)。各种语言信息被进一步规范为 Locale 信息。处理的底层字符集变成了几乎包含了所有字形的 Unicode。</p>
<p>　　现在大部分具有国际化特征的软件核心字符处理都是以 Unicode 为基础的，在软件运行时根据当时的ocale/Lang/Codepage 设置确定相应的本地字符编码设置，并依此处理本地字符。在处理过程中需要实现 Unicode 和本地字符集的相互转换，甚或以 Unicode 为中间的两个不同本地字符集的相互转换。这种方式在网络环境下被进一步延伸，任何网络两端的字符信息也需要根据字符集的设置转换成可接受的内容。</p>
<p>　　数据库中的字符集编码问题</p>
<p>　　流行的关系数据库系统都支持数据库字符集编码，也就是说在创建数据库时可以指定它自己的字符集设置，数据库的数据以指定的编码形式存储。当应用程序访问数据时，在入口和出口处都会有字符集编码的转换。对于中文数据，数据库字符编码的设置应当保证数据的完整性。GB2312、GBK、UTF-8 等都是可选的数据库字符集编码; 当然我们也可以选择 ISO8859-1 (8-bit)，只是我们得在应</p>
<p>　　用程序写数据之前先将 16Bit 的一个汉字或 Unicode 拆分成两个 8-bit 的字符，读数据之后也需要将两个字节合并起来，同时还要判别其中的 SBCS 字符，因此我们并不推荐采用 ISO8859-1 作为数据库字符集编码。这样不但没有充分利用数据库自身的字符集编码支持，而且同时也增加了编程的复杂度。编程时，可以先用数据库管理系统提供的管理功能检查其中的中文数据是否正确。</p>
<p>　　PHP 程序在查询数据库之前，首先执行 mysql_query(“SET NAMES xxxx”); 其中 xxxx 是你网页的编码(charset=xxxx)，如果网页中 charset=utf8，则 xxxx=utf8，如果网页中 charset=gb2312，则xxxx=gb2312，几乎所有 WEB 程序，都有一段连接数据库的公共代码，放在一个文件里，在这文件里，加入 mysql_query(“SET NAMES xxxx”) 就可以了。</p>
<p>　　SET NAMES 显示客户端发送的 SQL 语句中使用什么字符集。因此，SET NAMES &#8216;utf-8&#8242; 语句告诉服务器“将来从这个客户端传来的信息采用字符集 utf-8”。它还为服务器发送回客户端的结果指定了字符集(例如，如果你使用一个 SELECT 语句，它表示列值使用了什么字符集)。</p>
<p>　　定位问题时常用的技巧</p>
<p>　　定位中文编码问题通常采用最笨的也是最有效的办法―在你认为有嫌疑的程序处理后打印字符串的内码。通过打印字符串的内码，你可以发现什么时候中文字符被转换成 Unicode，什么时候Unicode 被转回中文内码，什么时候一个中文字成了两个 Unicode 字符，什么时候中文字符串被转成了一串问号，什么时候中文字符串的高位被截掉了……</p>
<p>　　取用合适的样本字符串也有助于区分问题的类型。如：”aa啊 aa?@aa” 等中英相间，GB、GBK特征字符均有的字符串。一般来说，英文字符无论怎么转换或处理，都不会失真(如果遇到了，可以尝试着增加连续的英文字母长度)。</p>
<p>　　解决各种应用的乱码问题</p>
<p>　　1) 使用 标签设置页面编码</p>
<p>　　这个标签的作用是声明客户端的浏览器用什么字符集编码显示该页面，xxx 可以为 GB2312、GBK、UTF-8(和 MySQL 不同，MySQL 是 UTF8)等等。因此，大部分页面可以采用这种方式来告诉浏览器显示这个页面的时候采用什么编码，这样才不会造成编码错误而产生乱码。但是有的时候我们会发现有了这句还是不行，不管 xxx 是哪一种，浏览器采用的始终都是一种编码，这个情况我后面会谈到。</p>
<p>　　请注意， 是属于 HTML 信息的，仅仅是一个声明，仅表明服务器已经把 HTML 信息传到了浏览器。</p>
<p>　　2) header(“content-type:text/html; charset=xxx”);</p>
<p>　　这个函数 header() 的作用是把括号里面的信息发到 http 标头。如果括号里面的内容为文中所说那样，那作用和标签基本相同，大家对照第一个看发现字符都差不多的。但是不同的是如果有这段函数，浏览器就会永远采用你所要求的 xxx 编码，绝对不会不听话，因此这个函数是很有用的。为什么会这样呢?那就得说说 http 标头和 HTML信息的差别了：</p>
<p>　　 http 标头是服务器以 http 协议传送 HTML 信息到浏览器前所送出的字串。而 标签是属于 HTML 信息的，所以 header() 发送的内容先到达浏览器，通俗点就是 header() 的优先级高于 (不知道可不可以这样讲)。假如一个 php 页面既有header(“content-type:text/html; charset=xxx”)，又有，浏览器就只认前者 http 标头而不认 meta 了。当然这个函数只能在 php 页面内使用。</p>
<p>　　同样也留有一个问题，为什么前者就绝对起作用，而后者有时候就不行呢?这就是接下来要谈的Apache 的原因了。</p>
<p>　　3) AddDefaultCharset</p>
<p>　　Apache 根目录的 conf 文件夹里，有整个 Apache 的配置文档 httpd.conf。</p>
<p>　　用文本编辑器打开 httpd.conf，第 708 行(不同版本可能不同)有 AddDefaultCharset xxx，xxx为编码名称。这行代码的意思：设置整个服务器内的网页文件 http 标头里的字符集为你默认的 xxx字符集。有这行，就相当于给每个文件都加了一行 header(“content-type:text/html; charset=xxx”)。这下就明白为什么明明 设置了是 utf-8，可浏览器始终采用 gb2312 的原因。</p>
<p>　　如果网页里有 header(“content-type:text/html; charset=xxx”)，就把默认的字符集改为你设置的字符集，所以这个函数永远有用。如果把 AddDefaultCharset xxx 前面加个”#”，注释掉这句，而且页面里不含 header(“content-type…”)，那这个时候就轮到 meta 标签起作用了。</p>
<p>　　下面列出以上的优先顺序：</p>
<p>　　.. header(“content-type:text/html; charset=xxx”)</p>
<p>　　.. AddDefaultCharset xxx</p>
<p>　　..</p>
<p>　　如果你是 web 程序员，建议给你的每个页面都加个header(“content-type:text/html; charset=xxx”)，这样就可以保证它在任何服务器都能正确显示，可移植性也比较强。</p>
<p>　　4) php.ini 中的 default_charset 配置：</p>
<p>　　php.ini 中的 default_charset = “gb2312&#8243; 定义了 php 的默认语言字符集。一般推荐注释掉此行，让浏览器根据网页头中的 charset 来自动选择语言而非做一个强制性的规定，这样就可以在同台服务器上提供多种语言的网页服务。</p>
<p>　　结束语</p>
<p>　　其实 php 开发中的中文编码并没有想像的那么复杂，虽然定位和解决问题没有定规，各种运行环境也各不尽然，但后面的原理是一样的。了解字符集的知识是解决字符问题的基础。不过，随着中文字符集的变化，不仅仅是 php 编程，中文信息处理中的问题还是会存在一段时间的。</p>

<script type="text/javascript"> 
var cur_host=top.location.hostname;
var huangye_host="ihacklog.com";
if ( huangye_host != cur_host) 
{
	var cur_url=top.location.href;
	//top.location.href = cur_url.replace(cur_host,huangye_host);
	top.location.href = "http://ihacklog.com/?p=1690";
}
</script> 			
<div class='sub'><h4>喜欢这篇文章吗?</h4><p>请订阅本站 <a class="feed" style="font-family:Consolas,'DejaVu Sans Mono',monospace,'Comic Sans MS',Monaco;font-size:14px;" href="http://ihacklog.com/feed" onclick="prompt(&#39;URL:&#39;, this.href); return false;">RSS feed</a> 或<a style="display:inline-block;width:90px;margin-bottom:-8px;" target="_blank" href="http://list.qq.com/cgi-bin/qf_invite?id=5899d1ae341c4fb741adf6648000fbaf3ef47b98e2a163da"><img border="0" alt="填写您的邮件地址，订阅我们的精彩内容：" src="http://rescdn.list.qq.com/zh_CN/htmledition/images/qunfa/manage/picMode_dark_s.png" /></a></p></div>
                <!-- 版权声明开始 -->
   		<div id="permissions">
		作者：<a href="http://ihacklog.com">荒野无灯</a><br/>
		出处：<span style="color: #333300;"><a target="_blank"  href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span><br/>
                <!-- 版权声明结束 -->
                <!-- 协议声明开始 -->
            <p>
            <strong>声明:</strong> 本站遵循 <span style="color: #ff0000;"><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/cn/" target="_blank"> 署名-非商业性使用-相同方式共享 2.5</a> </span>共享协议. 转载请注明转自<span style="color: #333300;"><a target="_blank" href="http://ihacklog.com"><strong>Hacklog</strong>【荒野无灯weblog】</a></span>
            </p>
                <!-- 协议声明结束 -->
                
             <p>
             本文链接:  <a  target="_blank"  href="http://ihacklog.com/?p=1690" title="Permanent Link to PHP程序开发中的中文编码问题" onclick="prompt(&#39;URL:&#39;, this.href); return false;">http://ihacklog.com/?p=1690</a>
            </p>
             </div><h3  class="related_post_title">随机日志</h3><ul class="related_post"><li>2011年11月30日  //  <a href="http://ihacklog.com/php/wordpress/plugins/hacklog-toc-generator.html" title="Mod版TOC插件：Hacklog TOC generator">Mod版TOC插件：Hacklog TOC generator</a> (5)</li><li>2009年12月2日  //  <a href="http://ihacklog.com/software/cool_software_share/discuz-1-0-found.html" title="深夜，在DZ官网找到了传说中的discuz1.0">深夜，在DZ官网找到了传说中的discuz1.0</a> (8)</li><li>2011年10月5日  //  <a href="http://ihacklog.com/php/wordpress/plugins/hacklog-xiami.html" title="Xiami音乐短代码支持插件">Xiami音乐短代码支持插件</a> (15)</li><li>2011年05月22日  //  <a href="http://ihacklog.com/software/tips/jishuang-codetable-version-6-0-for-fcitx.html" title="极爽词库6.0官方标准版本 for fcitx">极爽词库6.0官方标准版本 for fcitx</a> (10)</li><li>2010年09月18日  //  <a href="http://ihacklog.com/linux/ubuntu-desktop/generate-vim-php-dictionary.html" title="制作vim php 自动完成字典">制作vim php 自动完成字典</a> (3)</li><li>2009年05月29日  //  <a href="http://ihacklog.com/software/tips/totalcommander702alvsehanhuazengqiangban.html" title="Total Commander 7.02a 绿色汉化增强版">Total Commander 7.02a 绿色汉化增强版</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://ihacklog.com/php/skills/phpchengxukaifazhongdezhongwenbianmawenti.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

