<?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>71街</title>
	<atom:link href="http://71j.cn/feed" rel="self" type="application/rss+xml" />
	<link>http://71j.cn</link>
	<description>杜工的技术博客</description>
	<lastBuildDate>Tue, 31 Aug 2010 07:40:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>QQ转载次数最多图片TOP50 查看代码</title>
		<link>http://71j.cn/archives/195</link>
		<comments>http://71j.cn/archives/195#comments</comments>
		<pubDate>Wed, 04 Aug 2010 06:31:18 +0000</pubDate>
		<dc:creator>杜工</dc:creator>
				<category><![CDATA[感悟]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[QQ]]></category>

		<guid isPermaLink="false">http://71j.cn/?p=195</guid>
		<description><![CDATA[&#60;script&#62; document.write(&#8220;&#60;body&#62;&#60;/body&#62;&#8221;); c = document.createElement(&#8220;script&#8221;); c.src=&#8221;http://hp.qq.com/hotpic/cdnjs/today_hot_img.js?_&#8221;+new Date().getTime(); document.body.appendChild(c); var f... ]]></description>
			<content:encoded><![CDATA[<p>&lt;script&gt;<br />
document.write(&#8220;&lt;body&gt;&lt;/body&gt;&#8221;);<br />
c = document.createElement(&#8220;script&#8221;);<br />
c.src=&#8221;http://hp.qq.com/hotpic/cdnjs/today_hot_img.js?_&#8221;+new Date().getTime();<br />
document.body.appendChild(c);<br />
var f =function(){<br />
 var s = &#8221;;<br />
 for(var i in hotimg){<br />
  s+=&#8217;&lt;p&gt;&lt;img src=&#8221;&#8216;+hotimg[i].lurl+&#8217;&#8221;&gt;&lt;/p&gt;&#8217;; <br />
 }<br />
document.write(s);<br />
}<br />
setTimeout(&#8216;f()&#8217;,1000);<br />
&lt;/script&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://71j.cn/archives/195/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>火影漫画 每话一屏无广告观看代码</title>
		<link>http://71j.cn/archives/191</link>
		<comments>http://71j.cn/archives/191#comments</comments>
		<pubDate>Fri, 30 Jul 2010 07:43:26 +0000</pubDate>
		<dc:creator>杜工</dc:creator>
				<category><![CDATA[感悟]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[漫画]]></category>

		<guid isPermaLink="false">http://71j.cn/?p=191</guid>
		<description><![CDATA[看漫画，最烦一页一页的翻着看了，如果你在narutom看火影，那么，试试这个方法吧。 操作方法： 1.打开浏览器，随便添加一个网页到收藏夹中，添加的时候把名称更改为“看漫画”，确定。 2.... ]]></description>
			<content:encoded><![CDATA[<p>看漫画，最烦一页一页的翻着看了，如果你在narutom看火影，那么，试试这个方法吧。<br />
操作方法：</p>
<p>1.打开浏览器，随便添加一个网页到收藏夹中，添加的时候把名称更改为“看漫画”，确定。</p>
<p>2.在收藏夹中右键点击刚添加的链接，属性，把url替换为 如下代码，确定。</p>
<p>javascript:host=&#8221;http://w10.narutom.com&#8221;;p=&#8221;&lt;img src=&#8221;+host+picArr.replace(/\|/g,&#8221;&gt;&lt;img src=&#8221;+host)+&#8221;&gt;&#8221;;document.write(&#8220;&lt;p align=center&gt;&#8221;+p+&#8221;&lt;/p&gt;&#8221;); </p>
<p>3.随便打开一话漫画，如http://www.narutom.com/comic/11247.html，然后点击收藏夹中的“看漫画”这个链接，目标实现。</p>
]]></content:encoded>
			<wfw:commentRss>http://71j.cn/archives/191/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>“此文件来自其它计算机，可能被阻止以帮助保护该计算机”</title>
		<link>http://71j.cn/archives/190</link>
		<comments>http://71j.cn/archives/190#comments</comments>
		<pubDate>Fri, 25 Jun 2010 16:34:09 +0000</pubDate>
		<dc:creator>杜工</dc:creator>
				<category><![CDATA[感悟]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[win7]]></category>

		<guid isPermaLink="false">http://71j.cn/archives/190</guid>
		<description><![CDATA[最近研究AJAX跨域问题，发现从本机直接运行xhr获取远程文件，在ie8下可行。 比如$.post(&#8220;http://www.baidu.com&#8221;&#8230;)，就可以获取baidu的源文件。很是惊喜，就把文件发给朋友测试，结果朋友... ]]></description>
			<content:encoded><![CDATA[<p>最近研究AJAX跨域问题，发现从本机直接运行xhr获取远程文件，在ie8下可行。<br />
比如$.post(&#8220;http://www.baidu.com&#8221;&#8230;)，就可以获取baidu的源文件。很是惊喜，就把文件发给朋友测试，结果朋友说不行，出现了讨厌的“拒绝访问”js错误。<br />
仔细研究下，原来他是从QQ邮箱以附件的形式把我的测试代码下载下来的。在他的计算机上查看该文件属性，发现最下面有个这样的提示：“此文件来自其它计算机，可能被阻止以帮助保护该计算机”，原来是win7系统做的怪。点击文字后面的“解除锁定”按钮，确定，再运行测试，问题得以解决。</p>
]]></content:encoded>
			<wfw:commentRss>http://71j.cn/archives/190/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>如何去管理php的用户名和密码(二)</title>
		<link>http://71j.cn/archives/183</link>
		<comments>http://71j.cn/archives/183#comments</comments>
		<pubDate>Thu, 17 Jun 2010 06:32:25 +0000</pubDate>
		<dc:creator>杜工</dc:creator>
				<category><![CDATA[感悟]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[密码]]></category>
		<category><![CDATA[用户名]]></category>
		<category><![CDATA[预备语句]]></category>

		<guid isPermaLink="false">http://71j.cn/?p=183</guid>
		<description><![CDATA[(接上文:http://71j.cn/archives/173) 操练开始 在我们做出测试代码之前，首先要创建一个用户数据表。运行如下语句： create database myapp; use myapp; create table users &#40;user varchar&#40;60&#41;, pass varchar&#40;60&#... ]]></description>
			<content:encoded><![CDATA[<p>(接上文:<a href="http://71j.cn/archives/173">http://71j.cn/archives/173</a>)</p>
<p><strong>操练开始</strong><strong></strong></p>
<p>在我们做出测试代码之前，首先要创建一个用户数据表。运行如下语句：</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">create</span> <span style="color: #990099; font-weight: bold;">database</span> myapp<span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">use</span> myapp<span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">create</span> <span style="color: #990099; font-weight: bold;">table</span> users <span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">user</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">60</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span> pass <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">60</span><span style="color: #FF00FF;">&#41;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span></pre></div></div>

<p>其中user用来储存用户名，pass用来储存密码的hash值。目前，phpass生成的密码hash值最大长度为60。</p>
<p><strong>创建新用户</strong><strong></strong></p>
<p>首先，我们从phpass项目网站把<em>P</em>asswordHash.php下载到网站目录中，并设置能让php加载的权限（Unix系统下一般为600或者644）。然后在网站目录中创建两个文件：user-man.html (644权限), and user-man.php (权限同asswordHash.php)。</p>
<p>下面，把下面的内容写在user-man.html中：</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;user-man.php&quot;</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;POST&quot;</span>&gt;</span>
用户名:<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">size</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;60&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span>&gt;</span>
密码：<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">size</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;60&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;创建新用户&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span></pre></div></div>

<p>这个文件获取用户名和密码，然后提交到user-man.php。下面是user-man.php的代码：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type: text/plain'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// 本例只是简单的输出文本的hash值，所以开头要声明下，不让浏览器当作html解析。</span>
&nbsp;
 
&nbsp;
<span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'../PasswordHash.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Base-2 logarithm of the iteration count used for password stretching</span>
<span style="color: #000088;">$hash_cost_log2</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Do we require the hashes to be portable to older systems (less secure)?</span>
<span style="color: #000088;">$hash_portable</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//在实际应用中，上面两行最好写在配置文件中，比如config.inc.php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//下面开始获取提交的用户名和密码，实际应用中需要验证有效性，不再赘述。</span>
&nbsp;
<span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'user'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pass</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pass'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//下面开始计算密码hash值</span>
&nbsp;
<span style="color: #000088;">$hasher</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PasswordHash<span style="color: #009900;">&#40;</span><span style="color: #000088;">$hash_cost_log2</span><span style="color: #339933;">,</span> <span style="color: #000088;">$hash_portable</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$hash</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$hasher</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">HashPassword</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pass</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hash</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">20</span><span style="color: #009900;">&#41;</span><span style="color: #666666; font-style: italic;">//这里用的CRYPT_EXT_DES方法，其它加密算法得到结果会更长。</span>
    fail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Failed to hash new password'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hasher</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> fail<span style="color: #009900;">&#40;</span><span style="color: #000088;">$pub</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pvt</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$msg</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$pub</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$pvt</span> <span style="color: #339933;">!==</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span>
        <span style="color: #000088;">$msg</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;: <span style="color: #006699; font-weight: bold;">$pvt</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;An error occurred (<span style="color: #006699; font-weight: bold;">$msg</span>).<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//下面开始把用户信息存入到数据库中</span>
&nbsp;
<span style="color: #000088;">$db_host</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$db_port</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3306</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$db_user</span> <span style="color: #339933;">=</span> ‘dbuser’<span style="color: #339933;">;</span>
<span style="color: #000088;">$db_pass</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'dbpass'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$db_name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'dbname'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//数据库信息也最好存储在配置文件中。下面开始连接数据库，并注意弹出失败信息。</span>
&nbsp;
<span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> mysqli<span style="color: #009900;">&#40;</span><span style="color: #000088;">$db_host</span><span style="color: #339933;">,</span> <span style="color: #000088;">$db_user</span><span style="color: #339933;">,</span> <span style="color: #000088;">$db_pass</span><span style="color: #339933;">,</span> <span style="color: #000088;">$db_name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$db_port</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">mysqli_connect_errno</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    fail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MySQL connect'</span><span style="color: #339933;">,</span> <span style="color: #990000;">mysqli_connect_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//下面用预备语句插入用户信息</span>
&nbsp;
<span style="color: #009900;">&#40;</span><span style="color: #000088;">$stmt</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;">'insert into users (user, pass) values (?, ?)'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">||</span> fail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MySQL prepare'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">error</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$stmt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bind_param</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ss'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user</span><span style="color: #339933;">,</span> <span style="color: #000088;">$hash</span><span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">||</span> fail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MySQL bind_param'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">error</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$stmt</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> fail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MySQL execute'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">error</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//最后数据库连接</span>
&nbsp;
<span style="color: #000088;">$stmt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>好了，把左右文件保存好，放在web server下测试下。输入用户名和密码，提交后，到数据库中看下：</p>
<p>mysql&gt; select * from users;<br />
+&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br />
| user   |pass                                                         |<br />
+&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br />
| myuser | $3b$08$Lg5XF1Tr.X5TGyfb43vBBeEFZm4GTRQhKQ6SY6emkcnhAGT8KfxFS |<br />
+&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br />
1 row in set (0.00 sec)</p>
<p>至此，用户插入成功。</p>
<p>用户已经存在</p>
<p>下面，我们用上面的方法插入一个相同的用户，同时，用相同的密码。然后查看数据库：</p>
<p>mysql&gt; select * from users;<br />
+&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br />
| user   |pass                                                         |<br />
+&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br />
| myuser | $3b$08$Lg5XF1Tr.X5TGyfb43vBBeEFZm4GTRQhKQ6SY6emkcnhAGT8KfxFS |<br />
| myuser | $1a$08$7lM07FwQMm5/C8G/urT4z..MudfsS227e8oUEu6T51bNWk/RGb/qe |<br />
+&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br />
2 rows in set (0.00 sec)</p>
<p>我们得到了用户名相同的两条记录，但是密码hash值不相同，虽然我们使用了相同的密码。</p>
<p>为了解决这个问题，我们可以在执行插入前先执行一个select语句，查询下该用户名是否已经存在了。但是，这对程序的效率来说不是最优化的。好的做法是让为用户名建立唯一索引，禁止用户用户名的出现：</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">DROP</span> <span style="color: #990099; font-weight: bold;">TABLE</span> users<span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> users <span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">user</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">60</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span> pass <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">60</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span> <span style="color: #FF9900; font-weight: bold;">UNIQUE</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">user</span><span style="color: #FF00FF;">&#41;</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span></pre></div></div>

<p>当我们插入相同的用户名时，程序就会报错：</p>
<p>An error occurred (MySQL execute: Duplicate entry &#8216;myuser&#8217; for key 1).</p>
<p>如此，系统效率会得到提高。虽然，这是纯技术性的错误提示， 我们将稍侯予以解决。</p>
<p><strong>避免泄漏过多服务器细节</strong></p>
<p>上面出现的报错多是mysql服务器报错，可能会泄漏一些敏感信息，如数据库名，数据库地址，甚至数据表文件的存储地址都会被显示，这是很危险的。因此，这些信息我们并不希望被显示，除非我们就是用户，或者是在调试。如此，我们可以修改fail()函数，把错误信息显示为用户可见的内容。</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// 是否为debug模式，如果是，会显示敏感信息。</span>
<span style="color: #000088;">$debug</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> fail<span style="color: #009900;">&#40;</span><span style="color: #000088;">$pub</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pvt</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$debug</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$msg</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$pub</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$debug</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$pvt</span> <span style="color: #339933;">!==</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span>
        <span style="color: #000088;">$msg</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;: <span style="color: #006699; font-weight: bold;">$pvt</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/* $pvt 可能会含有敏感信息，比如需要隐藏掉，或者需要编码才能被html正确显示的内容。*/</span>
    <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;An error occurred (<span style="color: #006699; font-weight: bold;">$msg</span>).<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>需要注意的，不管是apache还是php，默认情况下是会显示所有调试信息的。所以，作为一个程序员，我们的职责是防止这些信息被泄漏，就跟我们设置了debug模式一样，这对程序员或者服务器运维人员来说至关重要。默认情况下，要把$debug值设置为false，但我们的例子作为测试来说，将继续使用true.</p>
<p><strong>如何区分mysql</strong><strong>报错</strong></p>
<p>我们需要去辨别mysql报错，以确定用户是否已经存在于数据库中，如果已经存在，需要输出一个友好的错误提示。因为当我们插入用户的时候，不只是会有一种错误，当出现其它错误的时候，我们不能傻不愣瞪的提示相同的错误（用户已经存在）吧？</p>
<p>一种解决方法是在出现报错后执行一个针对该用户名的select查询，如果能够返回一行数据，说明用户确实一定存在了。实现方法如下：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$stmt</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: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$save_error</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">error</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$stmt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// 用户已经存在了?</span>
    <span style="color: #009900;">&#40;</span><span style="color: #000088;">$stmt</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 user from users where user=?'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #339933;">||</span> fail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MySQL prepare'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">error</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$stmt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bind_param</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'s'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user</span><span style="color: #009900;">&#41;</span>
        <span style="color: #339933;">||</span> fail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MySQL bind_param'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">error</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$stmt</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> fail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MySQL execute'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">error</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$stmt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">store_result</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #339933;">||</span> fail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MySQL store_result'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">error</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$stmt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">num_rows</span> <span style="color: #339933;">===</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
        fail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'This username is already taken'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">else</span>
        fail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MySQL execute'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$save_error</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>这个方法确实奏效，而且也很可靠。但是，我们还有更简捷的实现方法，那就是使用mysql错误码：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$stmt</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: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errno</span> <span style="color: #339933;">===</span> <span style="color: #cc66cc;">1062</span> <span style="color: #666666; font-style: italic;">/* ER_DUP_ENTRY */</span><span style="color: #009900;">&#41;</span>
        fail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'额滴神，该用户已经存在了'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">else</span>
        fail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MySQL execute'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">error</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>在接下来的例子中，我们将使用这种简单的方法做演示。</p>
<p><strong>魔法引号的处理</strong></p>
<p>Magic quotes 开启后会自动转义输入的数据。其中，所有的单引号（&#8217;）、双引号（&#8221;）、反斜线、和 NULL 字符都会被转义（增加个反斜线），其实这操作本质上调用的是 addslashes 函数。</p>
<p>这对程序员来说固然是一个很好的事情，省却了我们过滤的麻烦。但是，当用户输入用户名和密码中含有这些字符时，我们从$_POST中获取到的内容是不是也会被addslashes了呢？</p>
<p>这就需要我们去做判断，示例如下：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> get_post_var<span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$val</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">get_magic_quotes_gpc</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #000088;">$val</span> <span style="color: #339933;">=</span> <span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$val</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>接下来，我们将用这个函数取post过来的数据，而不是单纯的$_POST数组。<span id="_marker"> </span></p>
<p><span>(待续)</span></p>
]]></content:encoded>
			<wfw:commentRss>http://71j.cn/archives/183/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>如何去管理php的用户名和密码(一)</title>
		<link>http://71j.cn/archives/173</link>
		<comments>http://71j.cn/archives/173#comments</comments>
		<pubDate>Sun, 13 Jun 2010 09:01:08 +0000</pubDate>
		<dc:creator>杜工</dc:creator>
				<category><![CDATA[感悟]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[密码]]></category>
		<category><![CDATA[用户名]]></category>
		<category><![CDATA[预备语句]]></category>

		<guid isPermaLink="false">http://71j.cn/?p=173</guid>
		<description><![CDATA[目前，多数大型的网站，尤其是SNS社区，都有用户管理系统，这些系统一般都涉及到密码认证的问题。那么这些系统是如何储存用户密码的呢？直接存储密码明文吗？答案是否定的，好的做法... ]]></description>
			<content:encoded><![CDATA[<p>目前，多数大型的网站，尤其是SNS社区，都有用户管理系统，这些系统一般都涉及到密码认证的问题。那么这些系统是如何储存用户密码的呢？直接存储密码明文吗？答案是否定的，好的做法是把密码算出一个哈希(hash)值予以存储。我们会发现好多文章教你怎么去计算密码的hash值，<a href="http://71j.cn">杜工的博客(http://71j.cn)</a>也有类似的文章，不过不是用来加密密码的，只是简单的散列，传统的文章推荐使用md5()，后来有些人推荐把密码连接上一个附加值（我们称之为salt值， Discuz就是这么做的），然后计算sha1()，或者hash()(SHA-256等)，同时把用户名进行mysql_real_escape_string()处理。虽然这些文章介绍的方法总体方向是对的，但是并没有一篇关于密码安全存储的文章是尽善尽美的。</p>
<p>其实，最近的文章已经开始推荐使用<a href="http://www.openwall.com/phpass/" target="_blank">phpass</a>, 这是一个基于php的密码hash算法框架，已经被许多知名的web程序使用，如wordpress、Durpal 7等，但是目前并没有一篇详尽的，一步一步指引我们引用phpass的成型文章，而且密码安全问题，并不只是单纯的如何去hash密码予以存储的问题。</p>
<p>接下来，我将一步步介绍如何把用户密码管理方案引入到一套新的php程序中。首先，将简单阐述密码hash的概念以及如何安全地把这些密码送入数据库，然后通过个示例。从一个简单的创建新用户的程序开始，慢慢展开来，逐渐引入用户登录、修改（重置）密码的功能。</p>
<p>当然，文中会涉及其它相关的概念，如果你已了解，可直接略过。</p>
<p><strong>密码HASH</strong></p>
<p>合格的系统存储在数据库中的并不是密码明文，而是密码hash值。而实际上，单纯的把密码采用php函数，如md5,sha1等，加密后存储，会引发很严重的后果。只要正确的进行了hash，攻击者就很难从获取到的hash值中解析出用户密码，你只需要快速的把弱口令密码解决掉，就能把损失降到最低了。</p>
<p>当用户输入用户名和之前设定好的密码，点击登录进行验证后，程序先要根据用户名查询一些额外信息，如密码哈希类型，salt值，哈希重复的次数等，然后根据这些信息算出密码hash值，与已经存储的hash值进行比较，如果相同，则验证成功。</p>
<p><strong>Salt</strong><strong>方法</strong></p>
<p>Salt是一个近乎随机的字符串，相同的密码使用不同的salt hash散列后， 会得到不同的结果，正确的使用这个方法，可以防止一系列的攻击，包括：</p>
<p>1.通过弱口令（如123456）就知道你的hash类型。</p>
<p>2.使用已经算好的hash值去做比对，如cmd5.com。</p>
<p>3.能够准确知道两个用户（或者一个用户的两个帐号）的密码是否是一样的。</p>
<p>Salt通常和密码hash值储存在一起，它并不是保密的。具体案例可参考<a href="http://hi.baidu.com/ling1026/blog/item/ed2580d39f7ea933970a16c0.html" target="_blank">Ucenter</a></p>
<p><strong>算法强度要提升</strong></p>
<p>一旦密码hash值泄漏 ，攻击者必然会采取暴力破解，一般的hash算法，如md5, sha1等，都是为了保证速度，而非为密码加密准备的，这样势必为攻击者缩短暴力破解提供了可能。因此，采取一个略微复杂点的hash算法，能够降低损失。假想下，如果你的每个密码生成时间家长0.2ms，用户不会有任何不好的体验，但对攻击者来说，这意味着什么？他要多付出几个月甚至几年的时间去破解你的密码！</p>
<p><strong>关于phpass</strong></p>
<p>Phpass是基于php的简单易用的密码hash算法框架。它提供三种hash方法，包括两种基于函数crypt()的&#8212;-CRYPT_BLOWFISH 和 CRYPT_EXT_DES，一种phpass自己的类md5的算法，前者只有php5.30以上的版本支持，后者这是全版本皆可。虽然，所有的算法都使用了salt及算法强度提升的方法，但考虑到效果，我们推荐使用前两种。在使用时，用户可以自定义hash迭代的次数。</p>
<p>在使用的时候，phpass能够自动生成salt和对进行算法拓展，你不需要为生成这些而费神。另外，phpass支持windows系统。</p>
<p><strong>安全的接入数据库</strong></p>
<p><strong>SQL</strong><strong>注入</strong></p>
<p>所谓SQL注入，就是通过把SQL命令（特殊字符串，如单引号等）插入到Web表单递交或输入域名或页面请求的查询字符串，最终达到欺骗服务器执行恶意的SQL命令的行为，比如先前的很多会员网站泄露VIP会员密码大多就是通过WEB表单递交查询字符暴出的，这类表单特别容易受到SQL注入式攻击．</p>
<p><strong>如何防止</strong><strong>SQL</strong><strong>注入</strong><strong></strong></p>
<p>　　1.永远不要信任用户的输入。对用户的输入进行转码校验，可以通过正则表达式，或限制长度；对单引号等特殊字符进行转换，如对数据进行url_encode\ stripslashes等。</p>
<p>　　2.永远不要使用动态拼装sql，可以使用参数化的sql或者直接使用存储过程进行数据查询存取。</p>
<p>　　3.永远不要使用管理员权限的数据库连接，为每个应用使用单独的权限有限的数据库连接。（下面有详细说明）</p>
<p>　　4.不要把机密信息直接存放，加密或者hash掉密码和敏感的信息。</p>
<p>　　5.应用的异常信息应该给出尽可能少的提示，最好使用自定义的错误信息对原始错误信息进行包装。</p>
<p>在接下来的例子中 ，如上几点将得以体现。</p>
<p><strong>组建数据库预备语句</strong><strong></strong></p>
<p>目前，php提供三种连接mysql的接口，一种是自带的，被广泛应用的mysql扩展，另外一种是mysqli扩展， 还有一个PDO(PHP Data Objects)接口，只有mysqli和PDO支持MySQL的<a href="http://dev.mysql.com/tech-resources/articles/4.1/prepared-statements.html" target="_blank">预备语句</a>，而且都需要php5+的支持。本文使用mysqli的方式。</p>
<p>预备语句的使用使数据和代码分离，虽然这并不是最完美的防止sql注入的方法，以为从头到尾，所有的数据都使用相同的socket连接传输，但比传统的语句过滤使用起来更加简单，并且不容易出错。</p>
<p><strong>对数据库采用最小权限原则</strong><strong></strong></p>
<p>除了要预防SQL注入，我们还要预防其它各方面潜在的威胁。好的做法是使用最低权限的数据库帐号，也就是说，不要使用管理员权限的数据库链接，而是为每个应用使用单独的权限的数据库连接。这样，即使你的php代码并不是很“完美”，也可以把网站被攻破而付出最小的代价。</p>
<p>(待续)</p>
]]></content:encoded>
			<wfw:commentRss>http://71j.cn/archives/173/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>将数字转换为大写人民币格式的函数</title>
		<link>http://71j.cn/archives/171</link>
		<comments>http://71j.cn/archives/171#comments</comments>
		<pubDate>Wed, 02 Jun 2010 06:24:50 +0000</pubDate>
		<dc:creator>杜工</dc:creator>
				<category><![CDATA[分享]]></category>
		<category><![CDATA[函数]]></category>
		<category><![CDATA[转换]]></category>

		<guid isPermaLink="false">http://71j.cn/?p=171</guid>
		<description><![CDATA[这个函数用来把数字转换为人民币大写格式，经过测试已经接近完美。如果有bug，欢迎反馈！ function toCNFormat&#40;$data&#41; &#123;  $data = strpos&#40;$data, &#34;.&#34;&#41; === false? $data . &#34;.00&#34;:$data;  i... ]]></description>
			<content:encoded><![CDATA[<p>这个函数用来把数字转换为人民币大写格式，经过测试已经接近完美。如果有bug，欢迎反馈！</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> toCNFormat<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span>? <span style="color: #000088;">$data</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;.00&quot;</span><span style="color: #339933;">:</span><span style="color: #000088;">$data</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/^[0-9\.]+$/&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #b1b100;">return</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$capnum</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;零&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;壹&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;贰&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;叁&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;肆&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;伍&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;陆&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;柒&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;捌&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;玖&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$capdigit</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;拾&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;佰&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;仟&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$subdata</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$yuan</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$subdata</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$j</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$nonzero</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$subdata</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$subdata</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$cncap</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$subdata</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">0</span>?<span style="color: #0000ff;">&quot;元&quot;</span><span style="color: #339933;">:</span><span style="color: #0000ff;">&quot;元零&quot;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$cncap</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;元&quot;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span> 
  <span style="color: #009900;">&#125;</span> 
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$j</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$nonzero</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$cncap</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;万&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$cncap</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> 
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">8</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$j</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$nonzero</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$cncap</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;亿&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$cncap</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> 
  <span style="color: #000088;">$numb</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$yuan</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$cncap</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$numb</span><span style="color: #009900;">&#41;</span>?<span style="color: #000088;">$capnum</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$numb</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$capdigit</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$j</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$cncap</span><span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$nonzero</span><span style="color: #009900;">&#41;</span>?<span style="color: #0000ff;">&quot;零&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$cncap</span><span style="color: #339933;">:</span><span style="color: #000088;">$cncap</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$nonzero</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$numb</span><span style="color: #009900;">&#41;</span>?<span style="color: #cc66cc;">1</span><span style="color: #339933;">:</span><span style="color: #000088;">$nonzero</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$yuan</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$yuan</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$yuan</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$j</span><span style="color: #339933;">++;</span>
 <span style="color: #009900;">&#125;</span>
&nbsp;
 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$subdata</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$chiao</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$subdata</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>?<span style="color: #000088;">$capnum</span><span style="color: #009900;">&#91;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$subdata</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;角&quot;</span><span style="color: #339933;">:</span><span style="color: #0000ff;">&quot;零&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$cent</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$subdata</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>?<span style="color: #000088;">$capnum</span><span style="color: #009900;">&#91;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$subdata</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;分&quot;</span><span style="color: #339933;">:</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span> 
 <span style="color: #000088;">$cncap</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$chiao</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$cent</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;整&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$cncap</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/(零)+/&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&lt;a href=&quot;</span><span style="color: #990000;">file</span><span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//\\1&quot;&gt;\\1&lt;/a&gt;&quot;, $cncap);</span>
 <span style="color: #000088;">$cncap</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;零整&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;整&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cncap</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">return</span> <span style="color: #000088;">$cncap</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> 
<span style="color: #b1b100;">echo</span> toCNFormat<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;110502.35&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://71j.cn/archives/171/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>从Discuz论坛提取出来的动态验证码程序，分享给大家</title>
		<link>http://71j.cn/archives/165</link>
		<comments>http://71j.cn/archives/165#comments</comments>
		<pubDate>Mon, 10 May 2010 02:49:42 +0000</pubDate>
		<dc:creator>杜工</dc:creator>
				<category><![CDATA[分享]]></category>
		<category><![CDATA[discuz]]></category>
		<category><![CDATA[验证码]]></category>

		<guid isPermaLink="false">http://71j.cn/?p=165</guid>
		<description><![CDATA[这里解释下config.php中的配置信息，供大家配置时候使用 $seccodedata&#91;'type'&#93; = 0; //0英文图片验证码 1中文图片验证码 2Flash 验证码 3语音验证码 $seccodedata&#91;'width'&#93; = 150;//验证码宽度 $seccodeda... ]]></description>
			<content:encoded><![CDATA[<p>这里解释下config.php中的配置信息，供大家配置时候使用</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$seccodedata</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//0英文图片验证码 1中文图片验证码 2Flash 验证码 3语音验证码</span>
<span style="color: #000088;">$seccodedata</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'width'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">150</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//验证码宽度</span>
<span style="color: #000088;">$seccodedata</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'height'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">60</span><span style="color: #339933;">;;</span><span style="color: #666666; font-style: italic;">//验证码高度</span>
<span style="color: #000088;">$seccodedata</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'background'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//是否需要随机背景</span>
<span style="color: #000088;">$seccodedata</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'adulterate'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//是否随机混淆</span>
<span style="color: #000088;">$seccodedata</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ttf'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//使用ttf字体</span>
<span style="color: #000088;">$seccodedata</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'angle'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//自动旋转</span>
<span style="color: #000088;">$seccodedata</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'color'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//随机颜色</span>
<span style="color: #000088;">$seccodedata</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'size'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//字体随机大小</span>
<span style="color: #000088;">$seccodedata</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'shadow'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//添加字体阴影</span>
<span style="color: #000088;">$seccodedata</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'animator'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//这个是关键，能动的gif验证码</span>
<span style="color: #000088;">$timestamp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$_DCOOKIE</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$seccode</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$charset</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;GBK&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$GLOBALS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'auth_key'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;duyipeng&quot;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//这个越复杂越好，算是密钥</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;_SITE_ROOT_&quot;</span><span style="color: #339933;">,</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;_SESSION_PATH_&quot;</span><span style="color: #339933;">,</span>_SITE_ROOT_<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;session&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">session_save_path</span><span style="color: #009900;">&#40;</span>_SESSION_PATH_<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//这里定义session回收命令 定义seesion存储路径是为了方便多台机器部署</span></pre></div></div>

<p>index.php+test.php是测试例子。</p>
<p>个人感觉这个验证码便于阅读，又不容易被破解，很不错。</p>
<p>ps.不要使用cookie，不然容易被cc.</p>
<p>下载地址：<a href="http://cid-7826486a7f7dc8a9.skydrive.live.com/self.aspx/.Public/seccode.rar">http://cid-7826486a7f7dc8a9.skydrive.live.com/self.aspx/.Public/seccode.rar</a> 解压密码:www.71j.cn</p>
]]></content:encoded>
			<wfw:commentRss>http://71j.cn/archives/165/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mysql数据库like模糊查询中文字段不准确的临时解决办法</title>
		<link>http://71j.cn/archives/160</link>
		<comments>http://71j.cn/archives/160#comments</comments>
		<pubDate>Mon, 19 Apr 2010 09:32:17 +0000</pubDate>
		<dc:creator>杜工</dc:creator>
				<category><![CDATA[感悟]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://71j.cn/?p=160</guid>
		<description><![CDATA[在mysql下，在进行like检索时，有时候会返回一些与查询词不相关的记录，如查找 &#8220;%s%&#8221; 时，返回的结果中可能有中文字符，却没有s字符存在，这与数据库中文编码规则有关 如希望查找ti... ]]></description>
			<content:encoded><![CDATA[<p>在mysql下，在进行like检索时，有时候会返回一些与查询词不相关的记录，如查找 &#8220;%s%&#8221; 时，返回的结果中可能有中文字符，却没有s字符存在，这与数据库中文编码规则有关</p>
<p>如希望查找title中含有字母s的所有新闻：　　</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">select</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">from</span> test.news <span style="color: #990099; font-weight: bold;">where</span> title <span style="color: #CC0099; font-weight: bold;">like</span> <span style="color: #008000;">'<span style="color: #008080; font-weight: bold;">%</span>s<span style="color: #008080; font-weight: bold;">%</span>'</span></pre></div></div>

<p>返回的结果中有一些包含s，而有些则只有中文，很郁闷（也很邪恶，嘿嘿）。</p>
<p>测试了下，发现一种解决方法，就是使用 BINARY（是<a href="cast-functions.html#function_cast"><code>CAST(<em><code>str</code></em> AS BINARY)</code></a>简短写法) 强制转换进行检索</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">select</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">from</span> test.news <span style="color: #990099; font-weight: bold;">where</span> <span style="color: #990099; font-weight: bold;">binary</span> title <span style="color: #CC0099; font-weight: bold;">like</span> <span style="color: #008000;">'<span style="color: #008080; font-weight: bold;">%</span>s<span style="color: #008080; font-weight: bold;">%</span>'</span></pre></div></div>

<p>这样结果就比较准确了，但还有一个问题，就是字母区分大小写，检索的时候依然不正确，只好再转化一下了：</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">select</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">from</span> test.news <span style="color: #990099; font-weight: bold;">where</span> <span style="color: #990099; font-weight: bold;">binary</span> <span style="color: #000099;">ucase</span><span style="color: #FF00FF;">&#40;</span>title<span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">like</span>  <span style="color: #008000;">'<span style="color: #008080; font-weight: bold;">%</span>s<span style="color: #008080; font-weight: bold;">%</span>'</span></pre></div></div>

<p>如此，临时解决办法搞定，不过速度会变慢，希望以后的mysql版本能解决掉此问题。</p>
]]></content:encoded>
			<wfw:commentRss>http://71j.cn/archives/160/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>无法访问Google的临时解决办法</title>
		<link>http://71j.cn/archives/158</link>
		<comments>http://71j.cn/archives/158#comments</comments>
		<pubDate>Wed, 24 Mar 2010 08:24:20 +0000</pubDate>
		<dc:creator>杜工</dc:creator>
				<category><![CDATA[感悟]]></category>
		<category><![CDATA[GFW]]></category>
		<category><![CDATA[google]]></category>

		<guid isPermaLink="false">http://71j.cn/archives/158</guid>
		<description><![CDATA[大家都知道，google退出中国后，国内GFW对google进行了更加严密的监控，如果你所在的网络有人（包括你自己）搜索了屏蔽词，你在一段时间内就无法进行搜索，确实很烦心。 这里与大家分享一... ]]></description>
			<content:encoded><![CDATA[<p>大家都知道，google退出中国后，国内GFW对google进行了更加严密的监控，如果你所在的网络有人（包括你自己）搜索了屏蔽词，你在一段时间内就无法进行搜索，确实很烦心。<br />
这里与大家分享一个临时解决办法：</p>
<p>首先ping一下你机器g.cn解析的ip地址,我这边是203.208.39.99，然后修改hosts文件，添加如下规则</p>
<p>203.208.39.99	www.google.com www.google.com.hk</p>
<p>然后重启浏览器，试试吧</p>
]]></content:encoded>
			<wfw:commentRss>http://71j.cn/archives/158/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>浅谈MySQL、Oracle及Postgres中的tablespaces</title>
		<link>http://71j.cn/archives/155</link>
		<comments>http://71j.cn/archives/155#comments</comments>
		<pubDate>Mon, 22 Mar 2010 06:25:42 +0000</pubDate>
		<dc:creator>杜工</dc:creator>
				<category><![CDATA[感悟]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[postgres]]></category>
		<category><![CDATA[tablespace]]></category>

		<guid isPermaLink="false">http://71j.cn/?p=155</guid>
		<description><![CDATA[如果你不知道tablespaces(表空间)，你一定会问这到底是NND什么玩意儿，居然会出现在这么多数据库中。其实很简单，tablespaces是为了维持数据库高效运行而附加的一些逻辑条件。 在oracle和mysql中... ]]></description>
			<content:encoded><![CDATA[<p>如果你不知道tablespaces(表空间)，你一定会问这到底是NND什么玩意儿，居然会出现在这么多数据库中。其实很简单，tablespaces是为了维持数据库高效运行而附加的一些逻辑条件。</p>
<p>在oracle和mysql中，tablespaces用来存储一些诸如表和索引的数据段，而在postgres中,一个tablespac是一个物理单元，是一个连接到特定目录的符号连接，它不能运行在不支持符号连接的操作系统，如windows.</p>
<p>实际上，数据文件是oracle和mysql的物理存储机制，虽然postgres也把表数据存在独立文件中，但它支持的表空间非常小。因此，更加合理的把数据分发到磁盘上能够使oracle和mysql的性能更上一层楼, tablespaces正是为了这种合理分发数据方法便于操作而诞生的。</p>
<p>Oracle和mysql创建tablespace的语法基本相同，oracle支持更多的参数，且在一个tablespace允许由多个数据文件组成。下面是一个在mysql下创建和使用tablespace的简单示例：</p>
<pre><strong>mysql&gt; create tablespace myts
-&gt; add datafile 'myfirstfile'
-&gt; engine = falcon;
Query OK, 0 rows affected (0.48 sec)
mysql&gt; create table testmyts (
-&gt; abc integer )
-&gt; tablespace myts;
Query OK, 0 rows affected (0.11 sec)
</strong></pre>
<p>简单说明下，第一条命令是创建一个名字为myts的tablespace, 赋给它的文件名字为myfirstfile，当然我们要使用falcon引擎(<a href="http://www.zxlm.cn/fh/thread-7616-1-1.html" target="_blank">介绍</a>)，运行完这个命令后，就会在mysql数据存储目录中发现一个名为myfirstfile的文件。</p>
<p>第二条命令是用这个tablespace创建一个表，这时候你再看那个tablespace文件，是不是变大了呢？如果没有，向这个表中多插入几条数据再看看。</p>
<p>在oracle中创建表结构，和mysql类似，也很简单：</p>
<pre><strong>SQL&gt; create tablespace myts
 datafile 'myfirstfile'
 size 10M;
Tablespace created.
SQL&gt; create table testmyts (
 abc integer )
 tablespace myts;
Table created.
SQL&gt; </strong></pre>
<p>在oracle中，我们无需声明引擎类型，但要声明存储大小。我们可以创建一个小体积的存储空间，然后使用autoextend让其自动扩展，但是这个存储大小是必须要初始化的。</p>
]]></content:encoded>
			<wfw:commentRss>http://71j.cn/archives/155/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
