<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[阿权的书房]]></title> 
<link>http://www.aslibra.com/blog/index.php</link> 
<description><![CDATA[技术经验分享，资料收集，偶尔晾几张相片，感言生活]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[阿权的书房]]></copyright>
<item>
<link>http://www.aslibra.com/blog/post/php_curl.php</link>
<title><![CDATA[curl的一些玩意]]></title> 
<author>hqlulu &lt;hqlulu@163.com&gt;</author>
<category><![CDATA[PHP]]></category>
<pubDate>Sat, 04 Sep 2010 08:39:40 +0000</pubDate> 
<guid>http://www.aslibra.com/blog/post/php_curl.php</guid> 
<description>
<![CDATA[ 
	最近在想是否可以打通各家微博，显然，新浪的没有什么难度，三下五除二就能够用curl撂倒。而腾讯就不太好做，各个登录入口都有图片验证，图片识别可就难度大了，可看某篇文章，看似也就是md5的问题，不需要图片识别。<br/><br/>登录网站的核心是cookie的问题，另外就是对代码的分析。<br/><br/>做个cookie的小实验：<br/><br/><a href="http://www.aslibra.com/teach/curl/need-cookie.php" target="_blank">need-cookie.php</a><br/><div class="code">&lt;?<br/>if($_GET&#91;&#039;login&#039;&#93;)&#123;<br/>&nbsp;&nbsp;$value = &#039;http://www.aslibra.com&#039;;<br/>&nbsp;&nbsp;setcookie(&quot;url&quot;, $value);<br/>&nbsp;&nbsp;exit;<br/>&#125;<br/><br/>if($_COOKIE&#91;&#039;url&#039;&#93;)&#123;<br/>&nbsp;&nbsp;echo &quot;thanks! your value is &quot;.$_COOKIE&#91;&#039;url&#039;&#93;;<br/>&#125;else&#123;<br/>&nbsp;&nbsp;echo &quot;Not permit&quot;;<br/>&#125;<br/>?&gt;</div><br/><br/><a href="http://www.aslibra.com/teach/curl/index.php" target="_blank">index.php</a><br/><div class="code">&lt;pre&gt;<br/>&lt;?<br/>$url = &quot;http://www.aslibra.com/teach/curl/need-cookie.php&quot;;<br/>$ckfile = &quot;cookie.txt&quot;;<br/><br/>echo &quot;== step 1 / no cookie ==&#92;n&quot;;<br/>$content = file_get_contents($url);<br/>echo $content.&quot;&#92;n&#92;n&quot;;<br/><br/>echo &quot;== step 2 / login ==&#92;n&quot;;<br/>$ch = curl_init( $url.&quot;?login=1&quot;);<br/>curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);<br/>curl_setopt($ch, CURLOPT_HEADER, 1);<br/>$r = curl_exec($ch);<br/>echo $r.&quot;&#92;n&#92;n&quot;;<br/><br/>echo &quot;== step 3 / get it with cookie ==&#92;n&quot;;<br/>$ch = curl_init( $url );<br/>curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);<br/>$r = curl_exec($ch);<br/>echo $r.&quot;&#92;n&#92;n&quot;;<br/><br/>?&gt;</div><br/><br/>执行结果：<br/><br/><div class="code">== step 1 / no cookie ==<br/>Not permit<br/><br/>== step 2 / login ==<br/>HTTP/1.1 200 OK<br/>Date: Sat, 04 Sep 2010 08:37:06 GMT<br/>Server: Apache/2.2.12 (Ubuntu)<br/>X-Powered-By: PHP/5.2.10-2ubuntu6.4<br/>Set-Cookie: url=http%3A%2F%2Fwww.aslibra.com<br/>Vary: Accept-Encoding<br/>Content-Length: 0<br/>Content-Type: text/html<br/><br/>1<br/><br/>== step 3 / get it with cookie ==<br/>thanks! your value is http://www.aslibra.com1</div><br/><br/>注意：第二步是有set-cookie的返回<br/><br/><strong>备注一下几篇文章：</strong><br/><br/>1 <a href="http://blog.webbang.net/works/1402/" target="_blank">新浪微博版twitese</a><br/>2 <a href="http://blog.webbang.net/tech/1406/" target="_blank">通过PHP curl向腾讯微博发送广播全过程</a><br/>3 <a href="http://coderscult.com/php/php-curl/2008/05/20/php-curl-cookies-example/" target="_blank">PHP cURL Cookies Example</a><br/>4 <a href="http://www.javaeye.com/topic/217381" target="_blank">csdn模拟登陆</a><br/>Tags - <a href="http://www.aslibra.com/blog/go.php/tags/php/" rel="tag">php</a> , <a href="http://www.aslibra.com/blog/go.php/tags/curl/" rel="tag">curl</a>
]]>
</description>
</item><item>
<link>http://www.aslibra.com/blog/post/google-voice-sms-php-api.php</link>
<title><![CDATA[转：Google Voice免费SMS短信发送API的PHP版代码]]></title> 
<author>hqlulu &lt;hqlulu@163.com&gt;</author>
<category><![CDATA[PHP]]></category>
<pubDate>Sun, 09 May 2010 10:22:18 +0000</pubDate> 
<guid>http://www.aslibra.com/blog/post/google-voice-sms-php-api.php</guid> 
<description>
<![CDATA[ 
	代码如下，测试过可行~ 中文会被忽略，不能纯中文<br/><br/><div class="code">&lt;?PHP<br/>/*<br/>Google Voice Api<br/>License&nbsp;&nbsp;:部分代码来自http://www.lostleon.com 增加了错误提示,返回信息,群发,中文转拼音&nbsp;&nbsp;所需PHP扩展：curl<br/>Author:threesky@gmail.com, http://www.heqee.com/<br/>*/<br/>class GoogleVoice<br/>&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;public $username;<br/>&nbsp;&nbsp;&nbsp;&nbsp;public $password;<br/>&nbsp;&nbsp;&nbsp;&nbsp;public $status;<br/>&nbsp;&nbsp;&nbsp;&nbsp;private $lastURL;<br/>&nbsp;&nbsp;&nbsp;&nbsp;private $login_auth;<br/>&nbsp;&nbsp;private $inboxURL = &#039;https://www.google.com/voice/m/&#039;;<br/>&nbsp;&nbsp;private $loginURL = &#039;https://www.google.com/accounts/ClientLogin&#039;;<br/>&nbsp;&nbsp;private $smsURL = &#039;https://www.google.com/voice/m/sendsms&#039;;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;public function __construct($username, $password)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;username = $username;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;password = $password;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/><br/>&nbsp;&nbsp;public function getLoginAuth()<br/>&nbsp;&nbsp;&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$login_param = &quot;accountType=GOOGLE&amp;Email=&#123;$this-&gt;username&#125;&amp;Passwd=&#123;$this-&gt;password&#125;&amp;service=grandcentral&amp;source=lostleonATgmailDOTcom-GoogleVoiceTool&quot;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$login_output = $this-&gt;curl($this-&gt;loginURL, $this-&gt;lastURL, $login_param);<br/>&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;login_auth = $this-&gt;match(&#039;/Auth=(&#91;A-z0-9_-&#93;+)/&#039;, $login_output, 1);<br/>&nbsp;&nbsp;&nbsp;&nbsp;return $this-&gt;login_auth;<br/>&nbsp;&nbsp;&#125;<br/><br/>&nbsp;&nbsp;public function get_rnr_se()<br/>&nbsp;&nbsp;&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$auth_param = &quot;?auth=&quot;.$this-&gt;getLoginAuth();<br/>&nbsp;&nbsp;&nbsp;&nbsp;$inbox_output = $this-&gt;curl($this-&gt;inboxURL.$auth_param, $this-&gt;lastURL);<br/>&nbsp;&nbsp;&nbsp;&nbsp;$_rnr_se = $this-&gt;match(&#039;!&lt;input.*?name=&quot;_rnr_se&quot;.*?value=&quot;(.*?)&quot;!ms&#039;, $inbox_output, 1);<br/>&nbsp;&nbsp;&nbsp;&nbsp;return $_rnr_se;<br/>&nbsp;&nbsp;&#125;<br/><br/>&nbsp;&nbsp;public function sms($to_phonenumber, $smstxt)<br/>&nbsp;&nbsp;&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$_rnr_se = $this-&gt;get_rnr_se();<br/>&nbsp;&nbsp;&nbsp;&nbsp;$sms_param = &quot;id=&amp;c=&amp;number=&quot;.urlencode($to_phonenumber).&quot;&amp;smstext=&quot;.urlencode($smstxt).&quot;&amp;_rnr_se=&quot;.urlencode($_rnr_se);<br/>&nbsp;&nbsp;&nbsp;&nbsp;$posturl = $this-&gt;smsURL.&quot;?auth=&quot;.$this-&gt;login_auth;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$sms_output = $this-&gt;curl($posturl, $this-&gt;lastURL, $sms_param);<br/>&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;status = $sms_output;<br/>&nbsp;&nbsp;&nbsp;&nbsp;return $sms_output;<br/>&nbsp;&nbsp;&#125;<br/><br/>&nbsp;&nbsp;private function curl($url, $referer = null, $post_param = null)<br/>&nbsp;&nbsp;&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$ch = curl_init($url);<br/>&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch, CURLOPT_HEADER, 0);<br/>&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);<br/>&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);<br/>&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch, CURLOPT_USERAGENT, &quot;Mozilla/5.0 (iPhone; U; CPU iPhone OS 2_2_1 like Mac OS X; en-us) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.1.1 Mobile/5H11 Safari/525.20&quot;);<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;if($referer)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch, CURLOPT_REFERER, $referer);<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;if(!is_null($post_param))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch, CURLOPT_POST, true);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch, CURLOPT_POSTFIELDS, $post_param);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;$html = curl_exec($ch);<br/>&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;lastURL = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);<br/>&nbsp;&nbsp;&nbsp;&nbsp;curl_close($ch);<br/>&nbsp;&nbsp;&nbsp;&nbsp;return $html;<br/>&nbsp;&nbsp;&#125;<br/><br/>&nbsp;&nbsp;private function match($regex, $str, $out_ary = 0)<br/>&nbsp;&nbsp;&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;return preg_match($regex, $str, $match) == 1 ? $match&#91;$out_ary&#93; : false;<br/>&nbsp;&nbsp;&#125;<br/><br/>&#125;<br/><br/>$voiceApi = new GoogleVoice(&#039;cevin1991@gmail.com&#039;,&#039;*******&#039;);<br/>echo $voiceApi-&gt;sms(&#039;8615022604794&#039;,&#039;testsadfasfasfa&#039;);</div><br/><br/><strong>参考阅读：</strong><br/><br/>1 数据源见前面说明<br/>2 另外可以参考更多内容：<br/><a href="http://posttopic.com/topic/google-voice-add-on-development" target="_blank">http://posttopic.com/topic/google-voice-add-on-development</a><br/>3 参考openID：<a href="http://code.google.com/intl/zh-CN/apis/accounts/docs/OpenID.html" target="_blank">http://code.google.com/intl/zh-CN/apis/accounts/docs/OpenID.html</a><br/>Tags - <a href="http://www.aslibra.com/blog/go.php/tags/google/" rel="tag">google</a> , <a href="http://www.aslibra.com/blog/go.php/tags/voice/" rel="tag">voice</a> , <a href="http://www.aslibra.com/blog/go.php/tags/sms/" rel="tag">sms</a> , <a href="http://www.aslibra.com/blog/go.php/tags/api/" rel="tag">api</a> , <a href="http://www.aslibra.com/blog/go.php/tags/php/" rel="tag">php</a>
]]>
</description>
</item><item>
<link>http://www.aslibra.com/blog/post/php-webshell.php</link>
<title><![CDATA[发现一个强大的webshell]]></title> 
<author>hqlulu &lt;hqlulu@163.com&gt;</author>
<category><![CDATA[PHP]]></category>
<pubDate>Tue, 20 Apr 2010 08:20:05 +0000</pubDate> 
<guid>http://www.aslibra.com/blog/post/php-webshell.php</guid> 
<description>
<![CDATA[ 
	<a href="http://pastebin.com/eWAT024P" target="_blank">点击这里查看webshell代码</a><br/><br/>webshell功能强大，学习的好代码，也提醒做运维安全的要有好的办法做预防啊！<br/><br/><strong>预防措施我觉得有几点：</strong><br/><br/>1 文件上传的限制<br/>2 对php文件的检查<br/>3 对于运行php进行路径限制<br/>4 对有危险的php用单独用户运行<br/><br/>第一点是对于恶意的php代码而言的，有些代码可能是你从别人那里复制过来的，做的不好，安全性不够，导致php文件上传到web目录。第二点对于ftp上传，或者php文件被修改的。第三点防止文件上传的，可以不执行文件上传路径的php。第四点是使用另外的用户运行，防止恶意修改别人的文件。<br/><br/>顺便说一下，pastebin网站的分享很有趣，我觉得蛮好的，可以随便贴点代码分享，功能比较的简洁实在。<br/>Tags - <a href="http://www.aslibra.com/blog/go.php/tags/php/" rel="tag">php</a>
]]>
</description>
</item><item>
<link>http://www.aslibra.com/blog/post/phpmyadmin-Synchronization.php</link>
<title><![CDATA[phpmyadmin新功能Synchronize]]></title> 
<author>hqlulu &lt;hqlulu@163.com&gt;</author>
<category><![CDATA[PHP]]></category>
<pubDate>Tue, 20 Apr 2010 08:17:43 +0000</pubDate> 
<guid>http://www.aslibra.com/blog/post/phpmyadmin-Synchronization.php</guid> 
<description>
<![CDATA[ 
	今天发现phpMyadmin3.3版本有两个新功能很实用：<br/>1 Synchronize是支持两个数据库同步的操作，这功能挺好的<br/>2 管理replication<br/><br/>不过，同步操作似乎是经过本地web管理的服务器，如果是远端的数据库同步，可能不太合适了，未确认。除非把管理的web端放在数据库的局域网，那样应该挺快。<br/><br/>复制的管理也蛮好，把平时需要输入的命令行给做成点击几下就可以，很方便，这个实用。<br/><br/>去<a href="http://www.phpmyadmin.net" target="_blank">phpmyadmin</a>官网下载最新版本吧！<br/><a href="http://www.phpmyadmin.net/documentation/documentation-gsoc/Synchronization_User_Manual.htm" target="_blank">点击这里查看官方关于同步功能的介绍</a><br/>Tags - <a href="http://www.aslibra.com/blog/go.php/tags/php/" rel="tag">php</a> , <a href="http://www.aslibra.com/blog/go.php/tags/mysql/" rel="tag">mysql</a>
]]>
</description>
</item><item>
<link>http://www.aslibra.com/blog/post/muti_fastcgi_server.php</link>
<title><![CDATA[独立的多个fastcgi端口服务]]></title> 
<author>hqlulu &lt;hqlulu@163.com&gt;</author>
<category><![CDATA[PHP]]></category>
<pubDate>Thu, 25 Mar 2010 12:17:23 +0000</pubDate> 
<guid>http://www.aslibra.com/blog/post/muti_fastcgi_server.php</guid> 
<description>
<![CDATA[ 
	建立两个独立的fastcgi服务会有一些好处：<br/><br/>1 不会因为某个网站进程占用特别多而影响别的网站，因为进程占用满了就没法处理了<br/>2 了解网站的压力<br/><br/>正常情况下，安装完fastcgi后，有如下文件：<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">etc/:<br/>pear.conf&nbsp;&nbsp;php-fpm.conf&nbsp;&nbsp;php.ini<br/><br/>sbin/:<br/>php-fpm</div></div><br/><br/>我们启动的是 sbin/php-fpm start<br/>看看文件内容：<br/><br/><div class="code">#! /bin/sh<br/><br/>php_fpm_BIN=/Data/apps/php-cgi/bin/php-cgi<br/>php_fpm_CONF=/Data/apps/php-cgi/etc/php-fpm.conf<br/>php_fpm_PID=/Data/apps/php-cgi/logs/php-fpm.pid<br/><br/><br/>php_opts=&quot;&quot;<br/># i.e. php_opts=&quot;--fpm-config $php_fpm_CONF&quot;<br/><br/>wait_for_pid () &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try=0<br/>.......</div><br/>看的出来，可以定义配置文件的路径，设置pid文件路径<br/>这两个都修改后，就可以了。<br/><br/>做如下修改：<br/><br/>1 复制一个php-fpm为9001（这里方便区分原先的9000端口的服务而已，看自己喜欢）<br/><br/><div class="code">#! /bin/sh<br/><br/>php_fpm_BIN=/Data/apps/php-cgi/bin/php-cgi<br/>php_fpm_CONF=/Data/apps/php-cgi/etc/php-fpm.9001.conf<br/>php_fpm_PID=/Data/apps/php-cgi/logs/php-fpm.9001.pid<br/><br/><br/>#php_opts=&quot;&quot;<br/>php_opts=&quot;--fpm-config $php_fpm_CONF&quot;</div><br/><br/>2 修改php-fpm.9001.conf文件<br/><br/><div class="code">&lt;value name=&quot;pid_file&quot;&gt;/Data/apps/php-cgi/logs/php-fpm.9001.pid&lt;/value&gt; <br/>&lt;value name=&quot;error_log&quot;&gt;/Data/apps/php-cgi/logs/php-fpm.9001.log&lt;/value&gt; <br/>&lt;value name=&quot;listen_address&quot;&gt;127.0.0.1:9001&lt;/value&gt;</div><br/><br/>3 启动即可 sbin/9001 start<br/>Tags - <a href="http://www.aslibra.com/blog/go.php/tags/linux/" rel="tag">linux</a> , <a href="http://www.aslibra.com/blog/go.php/tags/php/" rel="tag">php</a> , <a href="http://www.aslibra.com/blog/go.php/tags/fastcgi/" rel="tag">fastcgi</a>
]]>
</description>
</item><item>
<link>http://www.aslibra.com/blog/post/php_utf16_le_be.php</link>
<title><![CDATA[转换为UTF-16的新玩意]]></title> 
<author>hqlulu &lt;hqlulu@163.com&gt;</author>
<category><![CDATA[PHP]]></category>
<pubDate>Thu, 28 Jan 2010 13:34:26 +0000</pubDate> 
<guid>http://www.aslibra.com/blog/post/php_utf16_le_be.php</guid> 
<description>
<![CDATA[ 
	客户端需要UTF-16编码的文件，但转换时，同事说不对，要小尾序的，其实不太明白这个意思，查了一下资料。<br/><br/>PHP里的代码也就这样了：<br/><div class="code">$content = iconv(&#039;UTF-8&#039;, &#039;UTF-16&#039;, $content);</div><br/><br/>从某篇文章发现这样的东西：<br/><div class="code">from_to($string, &#039;UTF-16le&#039;, &#039;UTF-8&#039;);</div><br/><br/>这说明了有其它的UTF-16的编码方式，我们看看维基的说明《<a href="http://zh.wikipedia.org/zh-cn/UTF-16" target="_blank">UTF-16</a>》：<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">UTF-16是Unicode的其中一个使用方式。 UTF是 Unicode/UCS Transformation Format，即把Unicode转做某种格式的意思。<br/><br/>UTF-16的大尾序和小尾序储存形式都在用。一般来说，以Macintosh制作或储存的文字使用大尾序格式，以Microsoft或Linux制作或储存的文字使用小尾序格式。<br/><br/>字符“朱”：<br/>UTF-16LE 小尾序&nbsp;&nbsp;31 67 <br/>UTF-16BE 大尾序&nbsp;&nbsp;67 31 </div></div><br/><br/>PHP稍微修改一下就对了：<br/><div class="code">$content = iconv(&#039;UTF-8&#039;, &#039;UTF-16le&#039;, $content);</div><br/><br/>另外有这么个代码：<a href="http://hsivonen.iki.fi/php-utf8/" target="_blank">UTF-8 to Code Point Array Converter in PHP</a><br/>把字符都转换成代表的数字了，目前不知道什么用途。。<br/><br/>另外，需要转换PC格式为Unix格式时，需要在转换Utf-16之前处理，否则会出现好多乱码的哦<br/><div class="code">$content = str_replace(&quot;&#92;r&#92;n&quot;, &quot;&#92;n&quot;, $content);<br/>$content = iconv(&#039;UTF-8&#039;, &#039;UTF-16le&#039;, $content);</div><br/><br/>Tags - <a href="http://www.aslibra.com/blog/go.php/tags/php/" rel="tag">php</a> , <a href="http://www.aslibra.com/blog/go.php/tags/utf-16/" rel="tag">utf-16</a>
]]>
</description>
</item><item>
<link>http://www.aslibra.com/blog/post/php_iconv.php</link>
<title><![CDATA[PHP从UTF-8转换到GB2312时注意]]></title> 
<author>hqlulu &lt;hqlulu@163.com&gt;</author>
<category><![CDATA[PHP]]></category>
<pubDate>Mon, 25 Jan 2010 14:35:44 +0000</pubDate> 
<guid>http://www.aslibra.com/blog/post/php_iconv.php</guid> 
<description>
<![CDATA[ 
	从大的编码转换到小的编码，是会产生字符缩减的，甚至有些字在目标字符集里不存在。<br/><br/>比如gb2312里，“囧”、“镕”都会产生转换失败，但很奇怪，gb2312的网页里是有这样的文字的，有点不解。<br/>先看看官方的说明吧 <a href="http://php.net/manual/en/function.iconv.php" target="_blank">iconv</a><br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">out_charset <br/>The output charset. <br/><br/>If you append the string //TRANSLIT to out_charset transliteration is activated. This means that when a character can't be represented in the target charset, it can be approximated through one or several similarly looking characters. If you append the string //IGNORE, characters that cannot be represented in the target charset are silently discarded. Otherwise, str is cut from the first illegal character and an E_NOTICE is generated. </div></div><br/><br/><strong>看示例可知</strong><br/><br/>在输出字符里添加//TRANSLIT可以得到相近的意思的字符<br/>添加//IGNORE可以忽略不能转换的<br/>不添加，则在第一个错误的地方停止转换，也就是被截断了<br/><br/><strong>如何知道被截断了或者转换失败？</strong><br/><br/>有个例子可以参考一下（单位是字节还是字符，这里不确定）<br/><br/><div class="code">&lt;?<br/>//code from http://www.aslibra.com<br/>//code by hqlulu @ 2010-1-25<br/><br/>$title_origin = &quot;something&quot;;<br/>$title = iconv(&#039;utf-8&#039;, &#039;gb2312//IGNORE&#039;, $title_origin);<br/>$percent = round(strlen($title_origin)/strlen($title), 3);<br/><br/>//UTF-8汉字 3字节 gb2312汉字 2字节<br/>//最大比例为1.5，如果丢失文字，那就是有转换失败，并且比例变大<br/>//简单例子：“我”的urlencode值 = %E6%88%91(utf-8) = %CE%D2(gb2312)<br/><br/>if($percent &gt; 1.5 )&#123;<br/>&nbsp;&nbsp;$error&#91;&#93; = array(&#039;str&#039;, $title_origin);<br/>&#125;<br/>?&gt;</div><br/>Tags - <a href="http://www.aslibra.com/blog/go.php/tags/php/" rel="tag">php</a> , <a href="http://www.aslibra.com/blog/go.php/tags/iconv/" rel="tag">iconv</a>
]]>
</description>
</item><item>
<link>http://www.aslibra.com/blog/post/nginx_codeIgniter_config.php</link>
<title><![CDATA[nginx配置codeIgniter]]></title> 
<author>hqlulu &lt;hqlulu@163.com&gt;</author>
<category><![CDATA[PHP]]></category>
<pubDate>Thu, 14 Jan 2010 14:09:09 +0000</pubDate> 
<guid>http://www.aslibra.com/blog/post/nginx_codeIgniter_config.php</guid> 
<description>
<![CDATA[ 
	nginx配合codeIgniter有点麻烦，没有apache和lighttpd那么简单。<br/>在apache和lighttpd里面，判断 /index.php/sth 时，如果 /index.php是一个文件，就不会当做是文件路径了<br/><br/>我们可以这样简单的把某些路径rewrite，达到一样的效果：<br/>1 保持地址格式是 /index.php/control/model<br/>2 不产生404错误或者是no input的情况<br/><br/><div class="code">server &#123;<br/>&nbsp;&nbsp;index index.php index.htm;<br/>&nbsp;&nbsp;server_name&nbsp;&nbsp;www.aslibra.com;<br/>&nbsp;&nbsp;root&nbsp;&nbsp;&nbsp;&nbsp;/Data/webapps/www.aslibra.com;<br/><br/>&nbsp;&nbsp;location /book/ &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;if (!-e $request_filename) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rewrite ^/book/(.*)$ /book/index.php/$1 last;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;location /book/index.php &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;fastcgi_pass&nbsp;&nbsp; 127.0.0.1:9000;<br/>&nbsp;&nbsp;&nbsp;&nbsp;include&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fastcgi_params;<br/>&nbsp;&nbsp;&nbsp;&nbsp;fastcgi_param&nbsp;&nbsp;SCRIPT_FILENAME&nbsp;&nbsp;&nbsp;&nbsp;/Data/webapps/www.aslibra.com/book/index.php;<br/>&nbsp;&nbsp;&#125;<br/>&#125;</div><br/><br/><strong>我们还需要避免类似以下地址异常：</strong><br/><br/>/book/?test 404 查询字符会查找test的control<br/>/book/&test 错误 The URI you submitted has disallowed characters.<br/><br/>总体而言，是查询字符的问题，我们可以有两种方式处理：<br/><br/><strong>方式一：在codeIgniter处理之前避免</strong><br/><br/>我们定义系统使用REQUEST_URI来处理mvc参数，不修改系统的文件，我们修改自定义的文件<br/><br/>文件 application/config/config.php<br/>指定为REQUEST_URI方式处理，不是用auto，auto方式会判断查询字符<br/><br/><div class="code">&#124; &#039;AUTO&#039;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Default - auto detects<br/>&#124; &#039;PATH_INFO&#039;&nbsp;&nbsp;&nbsp;&nbsp;Uses the PATH_INFO<br/>&#124; &#039;QUERY_STRING&#039;&nbsp;&nbsp;Uses the QUERY_STRING<br/>&#124; &#039;REQUEST_URI&#039;&nbsp;&nbsp;&nbsp;&nbsp;Uses the REQUEST_URI<br/>&#124; &#039;ORIG_PATH_INFO&#039;&nbsp;&nbsp;Uses the ORIG_PATH_INFO<br/>&#124;<br/>*/<br/>$config&#91;&#039;uri_protocol&#039;&#93;&nbsp;&nbsp;= &quot;REQUEST_URI&quot;;</div><br/><br/>文件 index.php<br/>我们可以直接砍掉查询字符，保证参数不受影响<br/><br/><div class="code">//处理查询字符<br/>$url = explode(&#039;?&#039;, $_SERVER&#91;&#039;REQUEST_URI&#039;&#93;);<br/>$url = explode(&#039;&amp;&#039;, $url&#91;0&#93;);<br/>$_SERVER&#91;&#039;REQUEST_URI&#039;&#93; = $url&#91;0&#93;;<br/><br/>/*<br/>&#124;---------------------------------------------------------------<br/>&#124; LOAD THE FRONT CONTROLLER<br/>&#124;---------------------------------------------------------------<br/>&#124;<br/>&#124; And away we go...<br/>&#124;<br/>*/<br/>require_once BASEPATH.&#039;codeigniter/CodeIgniter&#039;.EXT;</div><br/><br/><strong>方式二：发生错误之后调整</strong><br/><br/>发生404错误时，我们自动跳转到相应的地址，比如去掉后面 ?xxxx 和 &xxxx<br/><br/>文件 application/errors/error_404.php<br/><br/><div class="code">&lt;?php<br/>$url = explode(&#039;?&#039;, $_SERVER&#91;&#039;REQUEST_URI&#039;&#93;);<br/>$url = explode(&#039;&amp;&#039;, $url&#91;0&#93;);<br/>if($url&#91;0&#93; != $_SERVER&#91;&#039;REQUEST_URI&#039;&#93;)&#123;<br/>&nbsp;&nbsp;echo &quot;&lt;meta http-equiv=&#92;&quot;refresh&#92;&quot; content=&#92;&quot;0;url=$url&#91;0&#93;&#92;&quot;&gt;&quot;;<br/>&#125;<br/>?&gt;<br/>&lt;/head&gt;</div><br/><br/>在 error_general.php 里也可以这样加一样的代码。<br/><br/>参考资料：<br/>1 不错的nginx配置方式，本文有参考: <a href="http://codeigniter.com/forums/viewthread/99180/" target="_blank">CodeIgniter Nginx Rewrite Rule</a><br/>2 <a href="http://route19.com/logbook/view/codeigniter-urls-nginx" target="_blank">CodeIgniter URLs & Nginx</a><br/>Tags - <a href="http://www.aslibra.com/blog/go.php/tags/nginx/" rel="tag">nginx</a> , <a href="http://www.aslibra.com/blog/go.php/tags/codeigniter/" rel="tag">codeigniter</a> , <a href="http://www.aslibra.com/blog/go.php/tags/php/" rel="tag">php</a>
]]>
</description>
</item><item>
<link>http://www.aslibra.com/blog/post/php_clear_img_attribute.php</link>
<title><![CDATA[PHP清理标签属性]]></title> 
<author>hqlulu &lt;hqlulu@163.com&gt;</author>
<category><![CDATA[PHP]]></category>
<pubDate>Fri, 25 Dec 2009 10:02:55 +0000</pubDate> 
<guid>http://www.aslibra.com/blog/post/php_clear_img_attribute.php</guid> 
<description>
<![CDATA[ 
	分享一段代码，平时在使用的<br/><div class="code">// code from http://www.aslibra.com/<br/>// by hqlulu<br/>// replace &lt;img (any code) src=&quot;(pic url)&quot;&gt;<br/>// to &lt;img src=&quot;(pic url)&quot;&gt;<br/><br/>function parse_img ( $content ) &#123;<br/>&nbsp;&nbsp;preg_match_all (&quot;/&lt;img&#91;^&gt;&#93;+src=&#92;&quot;(.+)&#92;&quot;&#91;^&gt;&#93;*&gt;/isU&quot;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;$content,<br/>&nbsp;&nbsp;&nbsp;&nbsp;$out, PREG_PATTERN_ORDER);<br/><br/>&nbsp;&nbsp;foreach($out&#91;1&#93; as $k=&gt;$v)&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$content = str_replace($out&#91;0&#93;&#91;$k&#93;, &#039;&lt;img src=&quot;&#039;.$out&#91;1&#93;&#91;$k&#93;.&#039;&quot;&gt;&#039;, $content);<br/>&nbsp;&nbsp;&#125;<br/><br/>&nbsp;&nbsp;return $content;<br/>&#125;</div><br/><br/>清理img标签里的其它属性，保留src，如果要清理别的，自行修改即可<br/>Tags - <a href="http://www.aslibra.com/blog/go.php/tags/php/" rel="tag">php</a>
]]>
</description>
</item><item>
<link>http://www.aslibra.com/blog/post/codeIgniter_hook_per_system_fix_uri.php</link>
<title><![CDATA[用hook解决codeIgniter里用户无意输入的查询字符]]></title> 
<author>hqlulu &lt;hqlulu@163.com&gt;</author>
<category><![CDATA[PHP]]></category>
<pubDate>Sun, 29 Nov 2009 16:54:17 +0000</pubDate> 
<guid>http://www.aslibra.com/blog/post/codeIgniter_hook_per_system_fix_uri.php</guid> 
<description>
<![CDATA[ 
	codeIgniter我用过一下，觉得比较的理想，很适合做开发，一个很小巧的php的MVC框架。<br/>由于是一个框架模式，所以样例代码拿过来是很容易看清楚程序架构的，也很容易参考，这比自己写的程序要好很多，至少你很容易找到每个代码的功能和位置。<br/><br/>碰到一个问题：<br/><br/>apache里面可以这样做rewrite<br/><br/><div class="code">&lt;VirtualHost *:80&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;ServerName&nbsp;&nbsp;&nbsp;&nbsp;www.aslibra.com<br/>&nbsp;&nbsp;&nbsp;&nbsp;DocumentRoot&nbsp;&nbsp;F:&#92;WebsiteLocal&#92;www.aslibra.com<br/>&nbsp;&nbsp;&nbsp;&nbsp;RewriteEngine On<br/>&nbsp;&nbsp;&nbsp;&nbsp;RewriteRule&nbsp;&nbsp; ^/(topic&#124;user)&nbsp;&nbsp;/index.php$0<br/>&nbsp;&nbsp;&nbsp;&nbsp;#RewriteRule&nbsp;&nbsp; ^/(topic&#124;user)&nbsp;&nbsp;/index.php?$0<br/>&lt;/VirtualHost&gt;</div><br/><br/>两种写法都可以让index.php处理此链接，而第一种是最好的，用户输入查询也没事，比如 /topic?test=ds<br/>第二种写法就不行了，会出现错误，地址匹配有特殊字符<br/>但对于nginx的服务器，是不能那样写的，如果按第一种写法，会出现404错误，当作目录了<br/>如果是lighttpd，那应该和apache类似，没有问题。<br/><br/><div class="code">location ~^/(topic&#124;user) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rewrite ^/(.*)&nbsp;&nbsp;/index.php?/$1 last;<br/>&#125;</div><br/><br/>出现的错误是：<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">An Error Was Encountered<br/>The URI you submitted has disallowed characters.</div></div><br/><br/>出自(系统库文件URI.php)：<br/><br/><div class="code">function _filter_uri($str)<br/>&#123;<br/>&nbsp;&nbsp;if ($str != &#039;&#039; &amp;&amp; $this-&gt;config-&gt;item(&#039;permitted_uri_chars&#039;) != &#039;&#039; &amp;&amp; $this-&gt;config-&gt;item(&#039;enable_query_strings&#039;) == FALSE)<br/>&nbsp;&nbsp;&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;// preg_quote() in PHP 5.3 escapes -, so the str_replace() and addition of - to preg_quote() is to maintain backwards<br/>&nbsp;&nbsp;&nbsp;&nbsp;// compatibility as many are unaware of how characters in the permitted_uri_chars will be parsed as a regex pattern<br/>&nbsp;&nbsp;&nbsp;&nbsp;if ( ! preg_match(&quot;&#124;^&#91;&quot;.str_replace(array(&#039;&#92;&#92;-&#039;, &#039;&#92;-&#039;), &#039;-&#039;, preg_quote($this-&gt;config-&gt;item(&#039;permitted_uri_chars&#039;), &#039;-&#039;)).&quot;&#93;+$&#124;i&quot;, $str))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;show_error(&#039;The URI you submitted has disallowed characters.&#039;, 400);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&#125;<br/><br/>&nbsp;&nbsp;// Convert programatic characters to entities<br/>&nbsp;&nbsp;$bad&nbsp;&nbsp;= array(&#039;$&#039;,&nbsp;&nbsp;&nbsp;&nbsp; &#039;(&#039;,&nbsp;&nbsp;&nbsp;&nbsp; &#039;)&#039;,&nbsp;&nbsp;&nbsp;&nbsp; &#039;%28&#039;,&nbsp;&nbsp;&nbsp;&nbsp; &#039;%29&#039;);<br/>&nbsp;&nbsp;$good&nbsp;&nbsp;= array(&#039;&amp;#36;&#039;,&nbsp;&nbsp;&#039;&amp;#40;&#039;,&nbsp;&nbsp;&#039;&amp;#41;&#039;,&nbsp;&nbsp;&#039;&amp;#40;&#039;,&nbsp;&nbsp;&#039;&amp;#41;&#039;);<br/><br/>&nbsp;&nbsp;return str_replace($bad, $good, $str);<br/>&#125;</div><br/><br/>看代码，我们可以设置config里面 enable_query_strings 为TRUE<br/>这次会得到什么结果：<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">404 Page Not Found<br/>The page you requested was not found.</div></div><br/><br/>这说明已经过了检查地址，到了路由这一部分了，这个错误是找不到相应的class/method所导致的<br/>重要的URI处理是在 _fetch_uri_string 函数里面，调用这个过滤器是在路由控制里面：<br/><br/>从Router.php里面找到（大概90行）<br/><br/><div class="code">// Fetch the complete URI string<br/>$this-&gt;uri-&gt;_fetch_uri_string();<br/>echo $this-&gt;uri-&gt;uri_string.&quot;&lt;hr&gt;&quot;; //检查</div><br/><br/>我们可以看到路由取出来的地址是什么，比较两种方式<br/>设置为：<br/><br/><div class="code">$config&#91;&#039;uri_protocol&#039;&#93;&nbsp;&nbsp;= &quot;AUTO&quot;;<br/>$config&#91;&#039;enable_query_strings&#039;&#93; = TRUE;</div><br/><br/>测试地址为： /topic/test?site=aslibra.com<br/>理想状态应该是进入 /topic/test<br/><br/>第一种情况，取得的uri为 site，这错的比较离谱<br/>第二种为 /topic，检查server变量<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">[QUERY_STRING] => /topic<br/>&nbsp;&nbsp;&nbsp;&nbsp;[REQUEST_URI] => /topic/test/?site=aslibra.com<br/>&nbsp;&nbsp;&nbsp;&nbsp;[SCRIPT_NAME] => /topic/test/<br/>&nbsp;&nbsp;&nbsp;&nbsp;[PHP_SELF] => /topic/test/<br/>&nbsp;&nbsp;&nbsp;&nbsp;[REQUEST_TIME] => 1259512731<br/>&nbsp;&nbsp;&nbsp;&nbsp;[argv] => Array<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[0] => /topic<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;[argc] => 1<br/>)</div></div><br/><br/>都发生了错误，修改auto为REQUEST_URI应该可以有救<br/>对于这个是支持，因为有正常的class和method，但如果是一级参数，那就出错了，比如<br/>/topic/?site=aslibra.com<br/><br/>这种情况最好的解决办法是钩子处理，在系统开始的时候把查询字符都忽略了<br/>或者，在index.php调用CI之前，就去掉，比如<br/><br/><div class="code">//code from http://aslibra.com/<br/>$tmp = explode(&#039;?&#039;,$_SERVER&#91;&#039;REQUEST_URI&#039;&#93;);<br/>$_SERVER&#91;&#039;REQUEST_URI&#039;&#93; = $tmp&#91;0&#93;;</div><br/><br/><strong>钩子方式的解决办法：</strong><br/><br/><div class="code">//配置里 $config&#91;&#039;enable_hooks&#039;&#93; = TRUE;<br/><br/>//config/hooks.php<br/>$hook&#91;&#039;pre_system&#039;&#93; = array(<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#039;class&#039;&nbsp;&nbsp;&nbsp;&nbsp;=&gt; &#039;Uri&#039;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#039;function&#039; =&gt; &#039;fix&#039;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#039;filename&#039; =&gt; &#039;Uri.php&#039;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#039;filepath&#039; =&gt; &#039;hooks&#039;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#039;params&#039;&nbsp;&nbsp; =&gt; &#039;&#039;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);</div><br/><br/>新建 hooks/Uri.php<br/><div class="code">&lt;?php <br/>//code from http://aslibra.com/<br/>class Uri&#123;<br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;function fix()&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$tmp = explode(&#039;?&#039;,$_SERVER&#91;&#039;REQUEST_URI&#039;&#93;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;$_SERVER&#91;&#039;REQUEST_URI&#039;&#93; = $tmp&#91;0&#93;;<br/>&nbsp;&nbsp;&#125;<br/>&#125;<br/>?&gt;</div><br/><br/>那修改auto为REQUEST_URI应该可以，查询字符支持可以不支持了<br/>Tags - <a href="http://www.aslibra.com/blog/go.php/tags/nginx/" rel="tag">nginx</a> , <a href="http://www.aslibra.com/blog/go.php/tags/apache/" rel="tag">apache</a> , <a href="http://www.aslibra.com/blog/go.php/tags/lighttpd/" rel="tag">lighttpd</a> , <a href="http://www.aslibra.com/blog/go.php/tags/php/" rel="tag">php</a> , <a href="http://www.aslibra.com/blog/go.php/tags/codeigniter/" rel="tag">codeigniter</a>
]]>
</description>
</item>
</channel>
</rss>