<?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://www.71j.cn/feed" rel="self" type="application/rss+xml" />
	<link>http://www.71j.cn</link>
	<description>杜工的技术博客</description>
	<lastBuildDate>Fri, 16 Dec 2011 03:52:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>网站安全性测试需要注意的一些问题</title>
		<link>http://www.71j.cn/archives/298</link>
		<comments>http://www.71j.cn/archives/298#comments</comments>
		<pubDate>Fri, 16 Dec 2011 01:57:23 +0000</pubDate>
		<dc:creator>杜工</dc:creator>
				<category><![CDATA[感悟]]></category>
		<category><![CDATA[网站测试]]></category>

		<guid isPermaLink="false">http://www.71j.cn/?p=298</guid>
		<description><![CDATA[https的访问有可能是用http方式也能够访问。 所有需要认证的页面都需要直接输入url 来验证 java的类都需要进行加密后才能够发布。（程序员完成） 所有的java页面报错有可能泄漏程序信息，所... ]]></description>
			<content:encoded><![CDATA[<ol>
<li>https的访问有可能是用http方式也能够访问。</li>
<li>所有需要认证的页面都需要直接输入url 来验证</li>
<li>java的类都需要进行加密后才能够发布。（程序员完成）</li>
<li>所有的java页面报错有可能泄漏程序信息，所有的页面都要加上异常</li>
<li>管理员的后台页面的用户名尽量长，密码也要尽量复杂。（程序员完成，不要使用ROOT ADMIN ADMINISTRATROR的字符）。</li>
<li>COOKIE中的不能包含明文的用户明和密码信息，最后能够将COOKIE的信息都加密。</li>
<li>如果获得一个用户的COOKIE文件，则不能够让用户直接不通过登陆就自动登录。</li>
<li>所有的输入字段都将英文的&lt;&gt; 屏蔽掉，防止用户输入恶意的JAVASCRIPT代码获取相应信息。</li>
<li>输入username’&#8211;这样的信息验证用户登录的健壮性。</li>
<li>url 中不能包含明文的密码和帐户信息</li>
<li>所有的重要提交页面提交后，再使用ie的返回后，则页面都应该提示页面已经过期，或者用户再次提交相同的信息，则系统能够提示此表单已经被提交过，不能在提交。</li>
<li>网页的session过期应该有时间限制，一般是30分钟，cookie也应该有30分钟过期限制（可根据业务的安全性而定）。</li>
<li>网页HTML中的hidden 的类型应该不包含敏感的认证信息和安全信息，防止他人盗用。</li>
</ol>
<p>&nbsp;</p>
<p>对于输入验证攻击的一些关键点：</p>
<ol>
<li>服务器端的输入验证，所有的字段前台输入后，后台程序都要进行判断有效性，而不是单纯的使用javascript来判断。</li>
<li>字符编码：HTML字符应该被当作编码，这样可以防止应用程序错误地解析他们。例如：将角扩号表示成“&amp;lt”和“&amp;gt”.屏蔽select （sel） insert update del grant revoke这些关键字的输入。</li>
<li>正则表达式：使用正则表达式来匹配未经授权的数据内容。</li>
<li>健壮的数据类型：数字值应该指派一个数字结构类型，字符值应当指派一个字符结构类型。长度限制在前台程序和后台程序都要加上判断。</li>
<li>所有异常都要使用try Catch来捕捉，或者使用errorpage的属性来定义不能捕获的异常信息，不能够将任何出错后的代码信息显示给用户。</li>
<li>要求认证，培植服务器，要求对每个目录中的所有文件都有恰当的认证。</li>
<li>使用最小权限访问 以尽可能低的权限的用户涨好赖运行web服务器上的应用程序。应用程序可能可以执行命令但是不能访问象/sbin这样的系统目录，因为只有具有root权限的用户才可以执行改目录中的命令。</li>
</ol>
<p>&nbsp;</p>
<p>关于防止sql语句注入的一些防范错误：</p>
<ol>
<li>健壮的错误处理：</li>
</ol>
<p>一定不要吧未经处理的odbc或者其他错误传递给用户。使用普通的错误页面和错误处理程序通知用户所发生的错误。但是不要提供系统信息、变量或其他数据。</p>
<ol>
<li>参数列表：</li>
</ol>
<p>将用户提供的数据存储到特定的变量中，字符串的连接是安全sql语句的最大隐患，因为它给用户提供了一种最简单的方法，用户可以使用单引号来操作sql语句。</p>
<p>在web 服务器上应该进行输入验证，而且数据库中的条目也应该有严格的类型定义。一个仅使用数值的字段应该被定义为int类型，而不是varchar类型。</p>
<ol>
<li>存储过程：</li>
</ol>
<p>用户自定义的存储过程更加难于进行sql注入。因为他们需要以特定的格式在特定的地方给出特定数量的参数，因此有许多前台条件需要满足。用户字定义的存储过程还可以提高性能。</p>
<ol>
<li>以较低的权限运行：数据库应用程序应该在最低权限下运行。同样，web服务器使用的用户账号也应该具有有限的功能。当然，该账号必须能对数据库进行读写操作，但是他不必修改master数据库或者执行备份的操作。</li>
<li>保护计划：</li>
</ol>
<p>表名、列名和sql的结构都不应在HTML中出现。不要将敏感信息放到用户能看到的页面文件的注释中。</p>
<ol>
<li>使用数据绊网：</li>
</ol>
<p>用模糊的方法进行保护的一个例外就是利用一些容易识别的文件存储假的用户ID和密码。用这些假文件中的用户ID登录就会警告支持人员有人已经非法进入到了应用程序的数据库，并且试图进一步行动。这个方法的缺点是，只有在有人注意到警告时，绊网才会起作用，这个需要有人进行实时监控。</p>
<ol>
<li>将数据写到高速光驱上，让敏感信息不能被改写。</li>
<li>数据伪装，将很多数据不要加密成很明显的加密形式，而是加密成很象正常数据的形式，这样黑客进入系统后拿到的数据也不能用。起到了欺骗的作用。</li>
<li>分布式的数据拷贝，将数据库的敏感文件放在不同的服务器上，这样黑客需要攻破多个数据库服务器才能够将数据获取。或者将敏感的数据库字段分别放在不同的数据库文件的表中，这样黑客和难获得完整的数据。</li>
<li>敏感的文件不要使用显示其真正用途的名字</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.71j.cn/archives/298/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>如何去管理php的用户名和密码(三)</title>
		<link>http://www.71j.cn/archives/295</link>
		<comments>http://www.71j.cn/archives/295#comments</comments>
		<pubDate>Thu, 15 Dec 2011 11:56:29 +0000</pubDate>
		<dc:creator>杜工</dc:creator>
				<category><![CDATA[感悟]]></category>
		<category><![CDATA[php mysql]]></category>

		<guid isPermaLink="false">http://www.71j.cn/?p=295</guid>
		<description><![CDATA[(接上文:http://71j.cn/archives/183) 用户传入数据的过滤 我们不能紧紧依靠mysql的过滤的机制，而需要对用户输入的变量进行非法字符过滤，防止DoS攻击和sql注入。 $user = get_post_var&#40;'user'&#41;; if&#40;!... ]]></description>
			<content:encoded><![CDATA[<p>(接上文:<a href="http://71j.cn/archives/183">http://71j.cn/archives/183</a>)</p>
<p><strong>用户传入数据的过滤</strong></p>
<p>我们不能紧紧依靠mysql的过滤的机制，而需要对用户输入的变量进行非法字符过滤，防止DoS攻击和sql注入。</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> get_post_var<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user'</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: #339933;">!</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/^[a-zA-Z0-9_]{1,60}$/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user</span><span style="color: #009900;">&#41;</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>
&nbsp;
<span style="color: #000088;">$pass</span> <span style="color: #339933;">=</span> get_post_var<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'pass'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/* 好歹我们也应该节省点CPU和内存吧，哈哈 */</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;">$pass</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">72</span><span style="color: #009900;">&#41;</span>
fail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'The supplied password is too long'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>这一步很关键。在每个项目中，我们都有专门的类来处理$_POST和$_GET过来的数据，保障数据安全。</p>
<p>&nbsp;</p>
<p><strong>验证用户身份</strong></p>
<p>一般开发过程中，从安全角度考虑，我们都不建议存储用户密码的明文，这是为什么呢？杜工卖个关子，读者自己思考吧。</p>
<p>&nbsp;</p>
<p>创建新用户：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><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>
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: #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: #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: #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;">'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;">$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>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><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 pass 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;">bind_result</span><span style="color: #009900;">&#40;</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_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>
<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;">fetch</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errno</span><span style="color: #009900;">&#41;</span>
fail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MySQL fetch'</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;">$hasher</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CheckPassword</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pass</span><span style="color: #339933;">,</span> <span style="color: #000088;">$hash</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$what</span><span style="color: #339933;">=</span> <span style="color: #0000ff;">'Authentication succeeded'</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;">$what</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Authentication failed'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</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></pre></div></div>

<p>&nbsp;</p>
<p>由此，验证过程完毕。非常安全。</p>
<p>&nbsp;</p>
<p><strong>修改密码</strong><strong></strong></p>
<p>修改密码前一定要验证原来的密码是否正确：</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: #000088;">$hasher</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CheckPassword</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pass</span><span style="color: #339933;">,</span> <span style="color: #000088;">$hash</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$what</span><span style="color: #339933;">=</span> <span style="color: #0000ff;">'Authentication succeeded'</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;">$what</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Authentication failed'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$op</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'fail'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Definitely not 'change'</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>随后进行密码规则判断，看是否符合要求，再进行update操作。</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$newpass</span> <span style="color: #339933;">=</span> get_post_var<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'newpass'</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;">$newpass</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">72</span><span style="color: #009900;">&#41;</span>
fail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'The new password is too long'</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;">$newpass</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>
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: #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;">'update users set pass=? 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;">'ss'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$hash</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>
&nbsp;
<span style="color: #000088;">$what</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Password changed'</span><span style="color: #339933;">;</span></pre></div></div>

<p>&nbsp;</p>
<p>这样，已经存在的用户密码就会被修改成功了。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.71j.cn/archives/295/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>杜工在windows下定时备份mysql的脚本</title>
		<link>http://www.71j.cn/archives/288</link>
		<comments>http://www.71j.cn/archives/288#comments</comments>
		<pubDate>Mon, 12 Dec 2011 12:32:03 +0000</pubDate>
		<dc:creator>杜工</dc:creator>
				<category><![CDATA[感悟]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.71j.cn/?p=288</guid>
		<description><![CDATA[嘿嘿，大家是不是经常为找不到windows下的定时备份脚本而苦恼（哭闹？），这里杜工分享下bat脚本做自动备份的例子，使用前请先安装WinRAR。 rem rem C:\Program Files &#40;x86&#41;\WinRAR 需要配置到系... ]]></description>
			<content:encoded><![CDATA[<p>嘿嘿，大家是不是经常为找不到windows下的定时备份脚本而苦恼（哭闹？），这里杜工分享下bat脚本做自动备份的例子，使用前请先安装WinRAR。</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">rem
rem C:\Program Files <span style="color: #66cc66;">&#40;</span>x86<span style="color: #66cc66;">&#41;</span>\WinRAR 需要配置到系统环境变量 path 下，才能调用rar cli工具
rem
rem 跳转到工作目录下
e:
cd e:\DBBAK
rem 设置备份文件名
<span style="color: #993333; font-weight: bold;">SET</span> BAK_FILE<span style="color: #66cc66;">=</span>MY_DBBAK_%<span style="color: #993333; font-weight: bold;">DATE</span>:~<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,-</span><span style="color: #cc66cc;">4</span>%<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">SQL</span>
rem 设置日志文件名
<span style="color: #993333; font-weight: bold;">SET</span> LOG_FILE<span style="color: #66cc66;">=</span>MY_DBBAK<span style="color: #66cc66;">.</span>log
rem 记录日志
echo <span style="color: #ff0000;">&quot;%date%&quot;</span> <span style="color: #66cc66;">&gt;&gt;</span> %LOG_FILE%
rem 开始dump
mysqldump <span style="color: #808080; font-style: italic;">--default-character-set=utf8 -hlocalhost -uroot -R --triggers --single-transaction -B mydb &gt; %BAK_FILE%</span>
rem 压缩备份文件
rar a %BAK_FILE%<span style="color: #66cc66;">.</span>rar %BAK_FILE%
rem 删除临时文件
del <span style="color: #66cc66;">/</span>F %BAK_FILE%
echo <span style="color: #ff0000;">&quot;%date%&quot;</span> <span style="color: #66cc66;">&gt;&gt;</span> %LOG_FILE%
echo <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #66cc66;">&gt;&gt;</span> %LOG_FILE%</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.71j.cn/archives/288/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PPT工具包分享–天天写PPT的XDJM们有福了</title>
		<link>http://www.71j.cn/archives/290</link>
		<comments>http://www.71j.cn/archives/290#comments</comments>
		<pubDate>Tue, 29 Nov 2011 10:32:41 +0000</pubDate>
		<dc:creator>杜工</dc:creator>
				<category><![CDATA[分享]]></category>

		<guid isPermaLink="false">http://www.71j.cn/?p=290</guid>
		<description><![CDATA[该工具包包含上百个优美鲜明的表现形式，各类人群都能从中找到所需的工具。 下载地址 pp... ]]></description>
			<content:encoded><![CDATA[<p>该工具包包含上百个优美鲜明的表现形式，各类人群都能从中找到所需的工具。</p>
<p><a href="http://alpha.lenovo.com.cn/wp-content/uploads/2011/11/20111129124026.jpg" rel="example4"><img src="http://alpha.lenovo.com.cn/wp-content/uploads/2011/11/20111129124026.jpg" alt="" width="667" height="314" /></a></p>
<p><a href="http://alpha.lenovo.com.cn/wp-content/uploads/2011/11/20111129123957.jpg" rel="example4"><img src="http://alpha.lenovo.com.cn/wp-content/uploads/2011/11/20111129123957.jpg" alt="" width="672" height="263" /></a></p>
<p>下载地址 <a href="http://alpha.lenovo.com.cn/wp-content/uploads/2011/11/ppt.zip">ppt</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.71j.cn/archives/290/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>gd库不支持jpeg的解决方法</title>
		<link>http://www.71j.cn/archives/283</link>
		<comments>http://www.71j.cn/archives/283#comments</comments>
		<pubDate>Sun, 06 Nov 2011 15:07:47 +0000</pubDate>
		<dc:creator>杜工</dc:creator>
				<category><![CDATA[感悟]]></category>
		<category><![CDATA[gd]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.71j.cn/?p=283</guid>
		<description><![CDATA[杜工就不在这里啰嗦怎么遇到这个问题的了，如果你确实安装了的gd库，却发现无法支持jpeg格式的图片，可从下面找到答案。 原因是在编译gd库前，配置时未声明jpeg库路径。解决方法如下： 32... ]]></description>
			<content:encoded><![CDATA[<p>杜工就不在这里啰嗦怎么遇到这个问题的了，如果你确实安装了的gd库，却发现无法支持jpeg格式的图片，可从下面找到答案。</p>
<p>原因是在编译gd库前，配置时未声明jpeg库路径。解决方法如下：</p>
<p>32位系统:</p>
<p>./configure &#8211;with-php-config=/usr/local/php5/bin/php-config<br />
&#8211;with-jpeg-dir=/usr/lib</p>
<p>64位系统</p>
<p>./configure &#8211;with-php-config=/usr/local/php5/bin/php-config<br />
&#8211;with-jpeg-dir=/usr/lib64</p>
<p>&nbsp;</p>
<p>重新make&amp;make install后，重启apache即可。</p>
<p>&nbsp;</p>
<p><a href="http://www.71j.cn/wp-content/uploads/2011/11/QQ截图20111106230800.jpg"><img class="aligncenter size-full wp-image-284" title="QQ截图20111106230800" src="http://www.71j.cn/wp-content/uploads/2011/11/QQ截图20111106230800.jpg" alt="" width="815" height="301" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.71j.cn/archives/283/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mysql服务无法启动,错误1067最快解决办法</title>
		<link>http://www.71j.cn/archives/280</link>
		<comments>http://www.71j.cn/archives/280#comments</comments>
		<pubDate>Tue, 01 Nov 2011 03:56:55 +0000</pubDate>
		<dc:creator>杜工</dc:creator>
				<category><![CDATA[感悟]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.71j.cn/?p=280</guid>
		<description><![CDATA[mysql 1067错误一般出现在windows系统下，自定义data目录路径的时候。即使是最新的mysql5.5 安装包，在安装完成进行配置时，也会出现这个问题。 杜工解决方法：将data目录设置在mysql安装目录下，... ]]></description>
			<content:encoded><![CDATA[<p>mysql 1067错误一般出现在windows系统下，自定义data目录路径的时候。即使是最新的mysql5.5 安装包，在安装完成进行配置时，也会出现这个问题。</p>
<p>杜工解决方法：将data目录设置在mysql安装目录下，可正常启动服务。</p>
<p>过程：安装msi文件，到最后一步配置时，可跳过，然后进入安装目录 /bin/下，找到MysqlInstanceConfig.exe，运行后，可按照提示一步一步配置。</p>
<p><a href="http://www.71j.cn/wp-content/uploads/2011/11/QQ截图20111101115650.jpg"><img class="aligncenter size-full wp-image-281" title="mysql config application" src="http://www.71j.cn/wp-content/uploads/2011/11/QQ截图20111101115650.jpg" alt="" width="825" height="374" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.71j.cn/archives/280/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Should&#8217;ve been invalidated iOS5开发错误</title>
		<link>http://www.71j.cn/archives/276</link>
		<comments>http://www.71j.cn/archives/276#comments</comments>
		<pubDate>Tue, 25 Oct 2011 08:43:02 +0000</pubDate>
		<dc:creator>杜工</dc:creator>
				<category><![CDATA[感悟]]></category>
		<category><![CDATA[iOS5]]></category>

		<guid isPermaLink="false">http://www.71j.cn/?p=276</guid>
		<description><![CDATA[iOS5推出后,赶紧升级手里的ios产品,发现有个错误始终无法解决,就是”Should&#8217;ve benn invalidated”,闪退. 排查了半天,最后发现是文件通过网络上传后,提前释放了连接导致的.把release行注释掉,程序... ]]></description>
			<content:encoded><![CDATA[<p>iOS5推出后,赶紧升级手里的ios产品,发现有个错误始终无法解决,就是”Should&#8217;ve benn invalidated”,闪退. 排查了半天,最后发现是文件通过网络上传后,提前释放了连接导致的.把release行注释掉,程序正常了.</p>
<p>leaks工具测试也通过.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.71j.cn/archives/276/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>objective-c 遍历表格的方法</title>
		<link>http://www.71j.cn/archives/273</link>
		<comments>http://www.71j.cn/archives/273#comments</comments>
		<pubDate>Thu, 25 Aug 2011 13:08:23 +0000</pubDate>
		<dc:creator>杜工</dc:creator>
				<category><![CDATA[感悟]]></category>
		<category><![CDATA[ios]]></category>
		<category><![CDATA[objective-c]]></category>

		<guid isPermaLink="false">http://www.71j.cn/?p=273</guid>
		<description><![CDATA[for &#40;int i = 0; i &#60; &#91;ptableView numberOfSections&#93;; i++&#41; &#123;     for &#40;int j = 0; j &#60; &#91;ptableView numberOfRowsInSection:i&#93;; j++&#41; &#123;         NSUInteger ints&#91;2&#93; = &#123;i,j&#125;;         NSInd... ]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> <span style="color: #009900;">&#91;</span>ptableView numberOfSections<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> j <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> j <span style="color: #339933;">&lt;</span> <span style="color: #009900;">&#91;</span>ptableView numberOfRowsInSection<span style="color: #339933;">:</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        NSUInteger ints<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>i<span style="color: #339933;">,</span>j<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        NSIndexPath <span style="color: #339933;">*</span>indexPath <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>NSIndexPath indexPathWithIndexes<span style="color: #339933;">:</span>ints length<span style="color: #339933;">:</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            UITableViewCell <span style="color: #339933;">*</span>cell <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>ptableView cellForRowAtIndexPath<span style="color: #339933;">:</span>indexPath<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
           <span style="color: #666666; font-style: italic;">//Here is your code</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>希望对你有帮助。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.71j.cn/archives/273/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>苹果应用开发,涉及到短信功能,如何提交商店审核呢?</title>
		<link>http://www.71j.cn/archives/267</link>
		<comments>http://www.71j.cn/archives/267#comments</comments>
		<pubDate>Sat, 06 Aug 2011 03:29:23 +0000</pubDate>
		<dc:creator>杜工</dc:creator>
				<category><![CDATA[感悟]]></category>
		<category><![CDATA[ios]]></category>

		<guid isPermaLink="false">http://www.71j.cn/?p=267</guid>
		<description><![CDATA[最近开发的乐助理360应用, 初次使用需要手机接受一条包含激活码的短信,  用户输入正确激活码后才能使用改应用. 所有的事情都做好了,杜工非常期待的提交给了苹果审核,结果人家给rejected了,... ]]></description>
			<content:encoded><![CDATA[<p>最近开发的乐助理360应用, 初次使用需要手机接受一条包含激活码的短信,  用户输入正确激活码后才能使用改应用. 所有的事情都做好了,杜工非常期待的提交给了苹果审核,结果人家给rejected了,原因是”我们收不到你们国家的短信,没法测试”,原文如下:</p>
<p>We began the review of your app but are not able to continue because we need demo phone number and verification code to fully access your app features. Please ensure that the demo account you provide includes any data necessary to demonstrate the functionality of your app features.</p>
<p>我了个去, 杜工怎么之前就没想到这点呢?于是一顿穷改, 加了一个固定的测试号码,只要输入这个号码,系统返回的激活码都是固定的就行了. 最后,重新提交审核,在review notes中客客气气的作下说明:</p>
<p>I&#8217;m sorry that our sms platform couldn&#8217;t send message to your country. So I added a special account as you mentioned in resolution center: 手机号码:130******* 激活码1234 So as long as you entered this phone No. exactly, the active code will always be 1234.<br />
For that and some bug-fixed, I upload a new binary. Thank&#8217;s for your kindly help and best regards.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.71j.cn/archives/267/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>为iphone数字键盘添加完成按钮</title>
		<link>http://www.71j.cn/archives/265</link>
		<comments>http://www.71j.cn/archives/265#comments</comments>
		<pubDate>Sat, 25 Jun 2011 13:35:37 +0000</pubDate>
		<dc:creator>杜工</dc:creator>
				<category><![CDATA[分享]]></category>
		<category><![CDATA[xcode]]></category>

		<guid isPermaLink="false">http://www.71j.cn/?p=265</guid>
		<description><![CDATA[If you have ever written an iPhone app that requires numeric input, then you surely know about the UIKeyboardTypeNumberPad. And if you have ever used that flavor of the iPhone&#8217;s keyboard, then you surely know that it lacks one very important featur... ]]></description>
			<content:encoded><![CDATA[<p>If you have ever written an iPhone app that requires numeric input,  then you surely know about the UIKeyboardTypeNumberPad. And if you have  ever used that flavor of the iPhone&#8217;s keyboard, then you surely know  that it lacks one very important feature: The UIKeyboardTypeNumberPad  does not have a “return” key.</p>
<p>In fact every other keyboard type (except for the pretty similar  UIKeyboardTypePhonePad) does offer the possibility to be dismissed by  setting the returnKeyType property of the corresponding  UITextInputTraits implementor. So how does one achieve the same effect  with the number pad? We have found a workround!</p>
<p>When looking at the number pad, you&#8217;ll notice that there is an unused  space on its bottom left. That&#8217;s where we are going to plug in our  custom “return” key.</p>
<p><img src="http://www.neoos.ch/images/stories/shotnodone.png" border="0" alt="" /></p>
<p>To make it short: take a screenshot, cut out the whole backspace key,  flip it horizotally, clear its backspace symbol in Photoshop and  overlay it with the text that we want on our “return” key. We’ve chosen  to label it “DONE”. Now we have the image for our custom  button’s UIControlStateNormal. Repeat the whole procedure (with a  touched backspace key when taking the screenshot) to get a second image  for our button’s UIControlStateHighlighted. Here’s the result:</p>
<p><img src="http://www.neoos.ch/images/stories/doneup.png" border="0" alt="" /> <img src="http://www.neoos.ch/images/stories/donedown.png" border="0" alt="" /></p>
<p>Now back to coding. First we need to know when the number pad is  going to be slided up on the screen so we can plug in our custom button  before that happens. Luckily there’s a notification for exactly that  purpose, and registering for it is as easy as:</p>
<pre> 
[[<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNotificationCenter_Class/">NSNotificationCenter</a> defaultCenter] addObserver:self
                                         selector:@selector(keyboardWillShow:)
                                             name:UIKeyboardWillShowNotification
                                           object:nil];</pre>
<p>Don&#8217;t forget to remove the observer from the notification center in the appropriate place once you&#8217;re done with the whole thing:</p>
<pre> 
[[<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNotificationCenter_Class/">NSNotificationCenter</a> defaultCenter] removeObserver:self];</pre>
<p>Now we’re getting to the heart of it. All we have to do in the  keyboardWillShow method is to locate the keyboard view and add our  button to it. The keyboard view is part of a second UIWindow of our  application as others have already figured out (see <a href="http://www.iphonedevsdk.com/forum/iphone-sdk-development/6275-add-toolbar-top-keyboard.html">this thread</a>).  So we take a reference to that window (it will be the second window in  most cases, so objectAtIndex:1 in the code below is fine), traverse its  view hierarchy until we find the keyboard and add the button to its  lower left:</p>
<pre> 
- (void)keyboardWillShow:(<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNotification_Class/">NSNotification</a> *)note {
    // create custom button
    UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
    doneButton.frame = CGRectMake(0, 163, 106, 53);
    doneButton.adjustsImageWhenHighlighted = NO;
    [doneButton setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal];
    [doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];
    [doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];

    // locate keyboard view
    UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
    UIView* keyboard;
    for(int i=0; i&lt;[tempWindow.subviews count]; i++) {
        keyboard = [tempWindow.subviews objectAtIndex:i];
        // keyboard view found; add the custom button to it
        if([[keyboard description] hasPrefix:@"&lt;UIKeyboard"] == YES)
            [keyboard addSubview:doneButton];
    }
}</pre>
<p>Voilà, that’s it! The empty space for our button starts at coordinate  (0, 163) and has the dimensions (106, 53). The doneButton method has to  be written now of course, but that’s not hard any more. Just make sure  that you call resignFirstResponder on the text field that is being  edited to have the keyboard slide down.</p>
<p><img src="http://www.neoos.ch/images/stories/shotwithdone.png" border="0" alt="" /></p>
<p>We’re “DONE”.</p>
<p>&nbsp;</p>
<p>本文例子 <a href="http://files.neoos.ch/KeyboardExtension.zip">downloaded as Xcode project</a><br />
更新: <a href="http://files.neoos.ch/KeyboardExtension_Updated.zip">download 3.0 compatible Xcode project</a>.<br />
最新的: <a href="http://files.neoos.ch/KeyboardExtension_2010.zip">download the newest version</a> (可运行 2.0 &#8211; 4.0所有版本)</p>
<p>&nbsp;</p>
<p>来源:http://www.neoos.ch/news/46-development/54-uikeyboardtypenumberpad-and-the-missing-return-key</p>
]]></content:encoded>
			<wfw:commentRss>http://www.71j.cn/archives/265/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

