<?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>LaoNi 的博客</title>
	<atom:link href="http://www.nixiaofeng.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.nixiaofeng.com</link>
	<description>Web Tec Developer</description>
	<lastBuildDate>Mon, 12 Mar 2012 02:56:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>本博不再更新，新文章请移步 http://blog.csdn.net/xfni</title>
		<link>http://www.nixiaofeng.com/652.html</link>
		<comments>http://www.nixiaofeng.com/652.html#comments</comments>
		<pubDate>Mon, 12 Mar 2012 02:56:29 +0000</pubDate>
		<dc:creator>LaoNi</dc:creator>
				<category><![CDATA[Default]]></category>

		<guid isPermaLink="false">http://www.nixiaofeng.com/?p=652</guid>
		<description><![CDATA[空间和域名即将到期，本博今后将不再使用本域名，新文章将更新到 http://blog.csdn.net/xfni]]></description>
			<content:encoded><![CDATA[<p>空间和域名即将到期，本博今后将不再使用本域名，新文章将更新到 <a href="http://blog.csdn.net/xfni">http://blog.csdn.net/xfni</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nixiaofeng.com/652.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>让WordPress自带插件焕发第二春 (2)</title>
		<link>http://www.nixiaofeng.com/646.html</link>
		<comments>http://www.nixiaofeng.com/646.html#comments</comments>
		<pubDate>Thu, 29 Sep 2011 17:23:34 +0000</pubDate>
		<dc:creator>LaoNi</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[blogroll]]></category>
		<category><![CDATA[multicolumn]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.nixiaofeng.com/?p=646</guid>
		<description><![CDATA[你一定考虑过，将友情链接分为2列显示，就像小博这样。 网上有篇转载了很多的文章，教我们实现了这个方法，它通过设置CSS的float属性，使得链接水平显示，同时一行显示不下就换行，这样看起来实现了分列显示友情链接的要求。 但是这个方法仅在IE下有效果，在Firefox、Chrome等非IE核心的浏览器中，因为没有做浮动清理，使得侧边栏略微破相了&#8211;Blogroll模块与下面的模块之间的间距显示错误。 我们需要完成2件事情： 1. 控制Blogroll显示为多列，列数可自定义。 2. 在必要的地方添加浮动清理（clear:both），使得页面不走形。 WP_Widget_Links插件在 /wp-includes/default-widgets.php 的85行开始，它会使用内置函数wp_list_bookmarks来显示友情链接，这个函数位于 /wp-includes/bookmark-template.php 中。 1. 首先修改wp_list_bookmarks函数，添加2个默认属性 “columns”列数，“widthpercolumn”每列宽度 找到wp_list_bookmarks函数，在201行的 $defaults 数组中添加2项： 表示默认显示1列，每列宽度100% 2. 输出CSS，以便在多列显示时运用 找到216行的 $output = &#8221;; 在下面加上： 表示在显示大于1列时输出这个CSS，起到多列显示的效果，并且每列的宽度根据widthpercolumn来设定。 3. 修改 _walk_bookmarks 函数，在必要的地方添加浮动清理 找到 _walk_bookmarks 函数，该函数同样位于/wp-includes/bookmark-template.php 中。 在51行的 $defaults 数组中添加一项： 表示默认按照1列显示 在 140行 的 $output .= &#8220;$after\n&#8221;; 之后添加如下代码，表示在每行结束后添加一个浮动清理 在紧接着下面的 // end … <a href="http://www.nixiaofeng.com/646.html"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
			<content:encoded><![CDATA[<p>你一定考虑过，将友情链接分为2列显示，就像小博这样。</p>
<p>网上有篇转载了很多的文章，教我们实现了这个方法，它通过设置CSS的float属性，使得链接水平显示，同时一行显示不下就换行，这样看起来实现了分列显示友情链接的要求。</p>
<p>但是这个方法仅在IE下有效果，在Firefox、Chrome等非IE核心的浏览器中，因为没有做浮动清理，使得侧边栏略微破相了&#8211;Blogroll模块与下面的模块之间的间距显示错误。</p>
<p><span id="more-646"></span><br />
我们需要完成2件事情：<br />
1. 控制Blogroll显示为多列，列数可自定义。<br />
2. 在必要的地方添加浮动清理（clear:both），使得页面不走形。</p>
<p>WP_Widget_Links插件在 /wp-includes/default-widgets.php 的85行开始，它会使用内置函数wp_list_bookmarks来显示友情链接，这个函数位于 /wp-includes/bookmark-template.php 中。</p>
<p>1. 首先修改wp_list_bookmarks函数，添加2个默认属性 “columns”列数，“widthpercolumn”每列宽度<br />
找到wp_list_bookmarks函数，在201行的 $defaults 数组中添加2项：</p>
<pre class="brush: php; title: ; notranslate">
'columns' =&gt; 1, 'widthpercolumn' =&gt; '100%'
</pre>
<p>表示默认显示1列，每列宽度100%</p>
<p>2. 输出CSS，以便在多列显示时运用<br />
找到216行的 $output = &#8221;; 在下面加上：</p>
<pre class="brush: php; title: ; notranslate">
if ($r['columns'] &gt; 1) {
$output .= &quot;\r\n&quot; . '' . &quot;\r\n&quot;;
}
</pre>
<p>表示在显示大于1列时输出这个CSS，起到多列显示的效果，并且每列的宽度根据widthpercolumn来设定。</p>
<p>3. 修改 _walk_bookmarks 函数，在必要的地方添加浮动清理<br />
找到 _walk_bookmarks 函数，该函数同样位于/wp-includes/bookmark-template.php 中。<br />
在51行的 $defaults 数组中添加一项：</p>
<pre class="brush: php; title: ; notranslate">
'columns' =&gt; 1
</pre>
<p>表示默认按照1列显示</p>
<p>在 140行 的 $output .= &#8220;$after\n&#8221;; 之后添加如下代码，表示在每行结束后添加一个浮动清理</p>
<pre class="brush: php; title: ; notranslate">
if ($r['columns'] &gt; 1) {
	if ($n == $r['columns']) {
		$output .= &quot;&lt;div style='clear:both'&gt;&lt;/div&gt;\n&quot;;
		$n = 0;
	}
	$n++;
}
</pre>
<p>在紧接着下面的 // end while 之后，添加如下代码，表示在输出完所有的链接后，在添加一个浮动清理</p>
<pre class="brush: php; title: ; notranslate">
$output .= &quot;&lt;div style='clear:both'&gt;&lt;/div&gt;\n&quot;;
</pre>
<p>到这里，我们把WP友情链接的函数给修改成可以显示多列了，我们可以使用如下方法调用出多列的友情链接列表：</p>
<pre class="brush: php; title: ; notranslate">
wp_list_bookmarks('columns=2&amp;widthpercolumn=45%');
</pre>
<p>5. 修改默认插件，添加多列选项<br />
在 /wp-includes/default-widgets.php 的 104行，$category = &#8230;之后添加2行默认参数：</p>
<pre class="brush: php; title: ; notranslate">
$columns = isset($instance['columns']) ? $instance['columns'] : 1;
$widthpercolumn = isset($instance['widthpercolumn']) ? $instance['widthpercolumn'] : '100%';
</pre>
<p>在 115行附近的 wp_list_bookmarks(apply_filters(&#8216;widget_links_args&#8217;, array(&#8230; 中添加2项</p>
<pre class="brush: php; title: ; notranslate">
'columns' =&gt; $columns, 'widthpercolumn' =&gt; $widthpercolumn
</pre>
<p>在 132行附近的 $instance['category'] = intval($new_instance['category']);后添加2行</p>
<pre class="brush: php; title: ; notranslate">
$instance['columns'] = intval($new_instance['columns']);
$instance['widthpercolumn'] = intval($new_instance['widthpercolumn']);
</pre>
<p>在最后，最后一个label for之后，添加2行</p>
<pre class="brush: php; title: ; notranslate">
&lt;input id=&quot;&lt;?php echo $this-&gt;get_field_id('columns'); ?&gt;&quot; type=&quot;text&quot; name=&quot;&lt;?php echo $this-&gt;get_field_name('columns'); ?&gt;&quot; value=&quot;&lt;?php echo $instance['columns'] ?&gt;&quot; size=&quot;2&quot; maxlength=&quot;1&quot; /&gt;&lt;label for=&quot;&lt;?php echo $this-&gt;get_field_id('columns'); ?&gt;&quot;&gt;&lt;!--?php _e('columns, each'); ?--&gt;&lt;/label&gt;
&lt;input id=&quot;&lt;?php echo $this-&gt;get_field_id('widthpercolumn'); ?&gt;&quot; type=&quot;text&quot; name=&quot;&lt;?php echo $this-&gt;get_field_name('widthpercolumn'); ?&gt;&quot; value=&quot;&lt;?php echo $instance['widthpercolumn'] ?&gt;&quot; size=&quot;3&quot; maxlength=&quot;3&quot; /&gt;&lt;label for=&quot;&lt;?php echo $this-&gt;get_field_id('widthpercolumn'); ?&gt;&quot;&gt;&lt;!--?php _e('px'); ?--&gt;&lt;/label&gt;
</pre>
<p>这样就在Wedget中添加了2个选项，可以方便的控制友情链接的显示了<br />
因为这个插件的修改涉及到了WP核心文件的修改，所以我觉得还是另外写一个插件比较合适。<br />
如果你觉得有用，可以在这里下载：<br />
<a href="http://www.nixiaofeng.com/wp-content/uploads/2011/09/wp-blogrollplus.zip">&gt;&gt;&gt;猛击下载&lt;&lt;&lt;</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nixiaofeng.com/646.html/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>让WordPress自带插件焕发第二春 (1)</title>
		<link>http://www.nixiaofeng.com/635.html</link>
		<comments>http://www.nixiaofeng.com/635.html#comments</comments>
		<pubDate>Mon, 26 Sep 2011 14:47:04 +0000</pubDate>
		<dc:creator>LaoNi</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[recent_comments]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.nixiaofeng.com/?p=635</guid>
		<description><![CDATA[WordPress自带了最新评论的插件，不过基本上没人会用，主要原因就是它无法显示评论的内容。 其实只要稍作修改，就能不必去找其他第三方插件，让自带插件为我所用。 在wp-includes找到default-widgets.php，这个就是自带的插件程序文件。 在其中找到 WP_Widget_Recent_Comments 这个类，它是自带的最新点评插件。 差不多在651行的位置，有一句 $output .= 语句，这就是插件输出内容的地方，其中有几个函数，这里解释一下： get_comment_author_link() 这是获取评论用户连接的函数，它返回了一个链接到评论者填写URL的超链接。 get_comment_link($comment->comment_ID) 这是获取评论链接的函数，它返回一个链接到评论所在页面的超链接。 get_the_title($comment->comment_post_ID) 这是获取文章主题的函数。 把651行的$output修改为： 就变成了本博客使用的最新点评样式了 解释一下其中多出来的几个函数： get_avatar( $comment, 48 ) 获取评论者头像，并制定大小为48px get_comment_author 返回评论者的名字 $comment->comment_content 评论的内容]]></description>
			<content:encoded><![CDATA[<p>WordPress自带了最新评论的插件，不过基本上没人会用，主要原因就是它无法显示评论的内容。<br />
其实只要稍作修改，就能不必去找其他第三方插件，让自带插件为我所用。</p>
<p>在wp-includes找到default-widgets.php，这个就是自带的插件程序文件。<br />
在其中找到 WP_Widget_Recent_Comments 这个类，它是自带的最新点评插件。</p>
<p><span id="more-635"></span><br />
差不多在651行的位置，有一句 $output .= 语句，这就是插件输出内容的地方，其中有几个函数，这里解释一下：</p>
<h3>get_comment_author_link()</h3>
<p>这是获取评论用户连接的函数，它返回了一个链接到评论者填写URL的超链接。</p>
<h3>get_comment_link($comment->comment_ID)</h3>
<p>这是获取评论链接的函数，它返回一个链接到评论所在页面的超链接。</p>
<h3>get_the_title($comment->comment_post_ID)</h3>
<p>这是获取文章主题的函数。</p>
<p>把651行的$output修改为：</p>
<pre class="brush: php; title: ; notranslate">
$output .= '&lt;li class=&quot;recentcomments&quot;&gt;';
// 输出头像（左浮动）
$output .= '&lt;div style=&quot;float:left; padding:4px 10px 4px 4px;&quot;&gt;';
$output .= get_avatar( $comment, 48 );
$output .= '&lt;/div&gt;';

// 输出评论人与评论内容（右浮动）
$output .= '&lt;div style=&quot;float:left; width:220px;&quot;&gt;'
$output .= '&lt;a href=&quot;' . esc_url(get_comment_link($comment-&gt;comment_ID)) . '&quot;&gt;' . get_comment_author() . '&lt;/a&gt;' . '&lt;br /&gt;';
$output .= '&lt;span style=&quot;font-size:13px;&quot;&gt;';
$output .= mb_strimwidth(strip_tags($comment-&gt;comment_content), 0, 64,&quot;...&quot;);
$output .= '&lt;/span&gt;'
$output .= '&lt;/div&gt;';
$output .= '&lt;div style=&quot;clear:both&quot;&gt;&lt;/div&gt;';
$output .= '&lt;/li&gt;';
</pre>
<p>就变成了本博客使用的最新点评样式了<br />
解释一下其中多出来的几个函数：</p>
<h3>get_avatar( $comment, 48 )</h3>
<p>获取评论者头像，并制定大小为48px</p>
<h3>get_comment_author</h3>
<p>返回评论者的名字</p>
<h3>$comment->comment_content</h3>
<p>评论的内容</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nixiaofeng.com/635.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>WP Super Cache 几个程序漏洞</title>
		<link>http://www.nixiaofeng.com/614.html</link>
		<comments>http://www.nixiaofeng.com/614.html#comments</comments>
		<pubDate>Fri, 23 Sep 2011 02:08:23 +0000</pubDate>
		<dc:creator>LaoNi</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[wp-supercache]]></category>
		<category><![CDATA[wrdpress]]></category>

		<guid isPermaLink="false">http://www.nixiaofeng.com/?p=614</guid>
		<description><![CDATA[这几天，小博的空间不太稳定，经常抽风。 昨天博客突然打不开，一直找不到原因，最后把Debug模式模式打开后，发现原来是WP-SuperCache突然出错，导致整个博客都显示空页面&#8230;&#8230;把我吓出一身冷汗。 到家后，查看了服务器的error-log，我NND，足足有8M，里面大多为PHP Notice警告。 警告内容主要是一些老旧的插件在WP升级了2.8之后，仍在使用一些兼容性的函数所致，将这些插件一一删除，报警逐渐减少，最后停留在WP-SuperCache的几个报错上。 在查看了一番代码后，将这几个错误修正，希望WP-SuperCache的后续版本可以修正一下这几个错误，毕竟用@符号屏蔽错误时需要消耗大量服务器资源的。 wp-cache.php，1896行，未定义键名&#8217;listfiles&#8217; 影响范围：WP-SuperCache后台，Contents标签 原因调查：listfiles作为get方法传递的参数，表示是否需要显示被缓存的文件列表，WP-SuperCache没有给出它的默认值，导致在判断变量值时出现undefined错误。 修改方法：很简单，WP-SuperCache没有判断是否存在键值，所以在1896行的if语句中加上 isset($_GET[ 'listfiles' ]) 就可以了 wp-cache.php，1997行，未定义变量&#8217;$cached_list&#8217; 影响范围：WP-SuperCache后台，Contents标签 原因调查：$cached_list中保存了Wordpress自带的缓存数据列表，这些缓存数据保存在 /wp-content/cache/meta 中，WP-SuperCache会检查这些数据，并显示出来。但是如果meta文件夹为空，那么就会出现undefined错误 修改方法：观察1997行的if语句 “if ( is_array( $cached_list ) &#38;&#38; !empty( $cached_list ) ) ”，只要定义一个空数组$cached_list就能解决问题，所以在 1888行加上 “$cached_list = array();” wp-cache.php，2014行，未定义变量&#8217;$expired_list&#8217; 影响范围：WP-SuperCache后台，Contents标签 原因调查：$expired_list保存了过期的WP-SuperCache缓存文件，清空缓存之后出现报错，与上一个问题同样，没有对$ecpired_list初始化，造成undefined错误。 修改方法：1889行加上 “$expired_list = array();” wp-cache-phase1.php，182行，未定义键名&#8217;HTTP_IF_MODIFIED_SINCE&#8217; 影响范围：前台 原因调查：$_SERVER服务器变量中没有HTTP_IF_MODIFIED_SINCE这个键名，导致出现undefined错误 修改方法： 187行的if语句 if ( function_exists( … <a href="http://www.nixiaofeng.com/614.html"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
			<content:encoded><![CDATA[<p>这几天，小博的空间不太稳定，经常抽风。</p>
<p>昨天博客突然打不开，一直找不到原因，最后把Debug模式模式打开后，发现原来是WP-SuperCache突然出错，导致整个博客都显示空页面&#8230;&#8230;把我吓出一身冷汗。</p>
<p>到家后，查看了服务器的error-log，我NND，足足有8M，里面大多为PHP Notice警告。</p>
<p>警告内容主要是一些老旧的插件在WP升级了2.8之后，仍在使用一些兼容性的函数所致，将这些插件一一删除，报警逐渐减少，最后停留在WP-SuperCache的几个报错上。</p>
<p>在查看了一番代码后，将这几个错误修正，希望WP-SuperCache的后续版本可以修正一下这几个错误，毕竟用@符号屏蔽错误时需要消耗大量服务器资源的。</p>
<p><span id="more-614"></span></p>
<h3>wp-cache.php，1896行，未定义键名&#8217;listfiles&#8217;</h3>
<p>
影响范围：WP-SuperCache后台，Contents标签<br />
原因调查：listfiles作为get方法传递的参数，表示是否需要显示被缓存的文件列表，WP-SuperCache没有给出它的默认值，导致在判断变量值时出现undefined错误。<br />
修改方法：很简单，WP-SuperCache没有判断是否存在键值，所以在1896行的if语句中加上 isset($_GET[ 'listfiles' ]) 就可以了
</p>
<h3>wp-cache.php，1997行，未定义变量&#8217;$cached_list&#8217;</h3>
<p>
影响范围：WP-SuperCache后台，Contents标签<br />
原因调查：$cached_list中保存了Wordpress自带的缓存数据列表，这些缓存数据保存在 /wp-content/cache/meta 中，WP-SuperCache会检查这些数据，并显示出来。但是如果meta文件夹为空，那么就会出现undefined错误<br />
修改方法：观察1997行的if语句 “if ( is_array( $cached_list ) &amp;&amp; !empty( $cached_list ) ) ”，只要定义一个空数组$cached_list就能解决问题，所以在 1888行加上 “$cached_list = array();”
</p>
<h3>wp-cache.php，2014行，未定义变量&#8217;$expired_list&#8217;</h3>
<p>
影响范围：WP-SuperCache后台，Contents标签<br />
原因调查：$expired_list保存了过期的WP-SuperCache缓存文件，清空缓存之后出现报错，与上一个问题同样，没有对$ecpired_list初始化，造成undefined错误。<br />
修改方法：1889行加上 “$expired_list = array();”
</p>
<h3>wp-cache-phase1.php，182行，未定义键名&#8217;HTTP_IF_MODIFIED_SINCE&#8217;</h3>
<p>
影响范围：前台<br />
原因调查：$_SERVER服务器变量中没有HTTP_IF_MODIFIED_SINCE这个键名，导致出现undefined错误<br />
修改方法：<br />
187行的if语句</p>
<pre>if ( function_exists( 'apache_request_headers' ) ) {
	$request = apache_request_headers();
	$remote_mod_time = $request[ 'If-Modified-Since' ];
} else {
	$remote_mod_time = $_SERVER[ 'HTTP_IF_MODIFIED_SINCE' ];
}</pre>
<p>修改为</p>
<pre>if ( function_exists( 'apache_request_headers' ) ) {
	$request = apache_request_headers();
	$remote_mod_time = $request[ 'If-Modified-Since' ];
} elseif (isset($_SERVER[ 'HTTP_IF_MODIFIED_SINCE' ])) {
	$remote_mod_time = $_SERVER[ 'HTTP_IF_MODIFIED_SINCE' ];
} else {
	$remote_mod_time = '';
}</pre>
</p>
<h3>wp-cache-phase2.php，988行，未定义变量&#8217;$wp_cache_object_cache&#8217;</h3>
<p>
影响范围：后台文章、页面发布及更新<br />
原因调查：全局变量 “$wp_cache_object_cache” 在函数内部未定义<br />
修改方法：967行最后，加上 $wp_cache_object_cache
</p>
<h3>wp-cache-phase2.php，946行，未定义变量&#8217;$dir&#8217;和&#8217;$permalink&#8217;</h3>
<p>
影响范围：后台文章、页面发布及更新<br />
原因调查：与947行、948行位置颠倒了<br />
修改方法：将946行放到948行下面就行了<br />
注意：这个错误仅会在开了WP-SuperCache的Debug后才会出现，是Debug中的一个BUG &#8211; -!!
</p>
<h3>wp-cache-phase2.php，973行，试图在一个非对象上使用对象操作符</h3>
<p>
影响范围：后台更换模板<br />
原因调查：在后台更换模板时，并没有获取任何日志，所以造成 get_post( $post_id ) 返回null，而不是日志对象<br />
修改方法：973行的 if语句中添加 !is_null($post)<br />
注意：这个错误仅会在开了WP-SuperCache的Debug后才会出现</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nixiaofeng.com/614.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Windows安装PHP，无法加载php_curl.dll的解决办法</title>
		<link>http://www.nixiaofeng.com/595.html</link>
		<comments>http://www.nixiaofeng.com/595.html#comments</comments>
		<pubDate>Tue, 20 Sep 2011 15:24:41 +0000</pubDate>
		<dc:creator>LaoNi</dc:creator>
				<category><![CDATA[web]]></category>
		<category><![CDATA[Web Server]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[php_curl.dll]]></category>

		<guid isPermaLink="false">http://www.nixiaofeng.com/?p=595</guid>
		<description><![CDATA[今天在笔记本上配置开发环境，安装PHP时将所有组件都安装了，发现Apache从此就无法启动，逐个禁用PHP组件后发现，除了oci几个dll因为没有安装Oracle客户端之外，php_curl.dll只要一加载就无法启动 研究了半天，鼓捣出来了，原来是php_curl.dll相关的2个lib文件没有加载。 只要在Apache配置文件中加上2句： LoadFile "D:/webserver/php/ssleay32.dll" LoadFile "D:/webserver/php/libeay32.dll" OK，问题解决]]></description>
			<content:encoded><![CDATA[<p>今天在笔记本上配置开发环境，安装PHP时将所有组件都安装了，发现Apache从此就无法启动，逐个禁用PHP组件后发现，除了oci几个dll因为没有安装Oracle客户端之外，php_curl.dll只要一加载就无法启动</p>
<p>研究了半天，鼓捣出来了，原来是php_curl.dll相关的2个lib文件没有加载。</p>
<p>只要在Apache配置文件中加上2句：</p>
<pre>
LoadFile "D:/webserver/php/ssleay32.dll"
LoadFile "D:/webserver/php/libeay32.dll"
</pre>
<p>OK，问题解决</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nixiaofeng.com/595.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Apache Forbidden 403错误</title>
		<link>http://www.nixiaofeng.com/593.html</link>
		<comments>http://www.nixiaofeng.com/593.html#comments</comments>
		<pubDate>Fri, 16 Sep 2011 15:59:15 +0000</pubDate>
		<dc:creator>LaoNi</dc:creator>
				<category><![CDATA[web]]></category>
		<category><![CDATA[Web Server]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[forbidden]]></category>

		<guid isPermaLink="false">http://www.nixiaofeng.com/?p=593</guid>
		<description><![CDATA[在公司将框架的源码拷贝回家，准备在家里也搭一个运行环境，但配置好的Apache怎么都显示 Fobidden 遂打开Apache日志查看，发现所有的访问都显示这条错误： Directory index forbidden by Options directive: D:/Develope/vhosts/framework/ 首页被某个选项设定为禁止访问 再次打开Apache vhost配置文件，仔细端详 &#60;Directory &#8220;D:\Develope\vhosts\framework&#8221;&#62; Options Indexes FollowSymLinks AllowOverride All Order allow,deny Deny from all &#60;/Directory&#62; 原来是这家伙在捣鬼 改成Allow 晕，首页把文件目录列出来了，而不是显示页面 加上 DirectoryIndex index.php 默认首页是index.php OK，解决]]></description>
			<content:encoded><![CDATA[<p>在公司将框架的源码拷贝回家，准备在家里也搭一个运行环境，但配置好的Apache怎么都显示 Fobidden<br />
遂打开Apache日志查看，发现所有的访问都显示这条错误：</p>
<p>Directory index forbidden by Options directive: D:/Develope/vhosts/framework/<br />
首页被某个选项设定为禁止访问</p>
<p>再次打开Apache vhost配置文件，仔细端详<br />
&lt;Directory &#8220;D:\Develope\vhosts\framework&#8221;&gt;<br />
Options Indexes FollowSymLinks<br />
AllowOverride All<br />
Order allow,deny<br />
<span style="color: #ff0000;">Deny</span> from all<br />
&lt;/Directory&gt;</p>
<p>原来是这家伙在捣鬼<br />
改成Allow<br />
晕，首页把文件目录列出来了，而不是显示页面<br />
加上 DirectoryIndex index.php 默认首页是index.php<br />
OK，解决</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nixiaofeng.com/593.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP框架初步写完进入调试阶段</title>
		<link>http://www.nixiaofeng.com/576.html</link>
		<comments>http://www.nixiaofeng.com/576.html#comments</comments>
		<pubDate>Thu, 15 Sep 2011 10:44:18 +0000</pubDate>
		<dc:creator>LaoNi</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.nixiaofeng.com/?p=576</guid>
		<description><![CDATA[终于，经历重重磨难，与9月15日晚将框架的主要功能调试通过，下面简单介绍下这个框架。 运行环境： Apache2 or later (需要mod_rewrite) PHP5 or later 下载地址：[0.1.1-alpha Download] 0.1.1-alpha是开发版，部分功能尚未完成，所有功能都未经过详细Debug，不能用于生产环境 主要功能： 1. 构建清晰的URL地址 2. 支持多种数据库（目前仅支持Mysql，更多的数据库支持会在将来提供） 3. 内建Memcache支持 4. 如果服务器不支持Memcache，内建HardDisk Cache 临时代替 Memcache 5. 模板化前端HTML（借用Smarty） 接着要做的工作： 1. 构建oracle数据库支持 2. 将Memcache从数据库剥离（目前和数据库封装在一起） 3. 重新整理调用关系，使逻辑上更加清晰 4. 内建各种支持库文件，方便使用 能想到的就是这些，源码稍后放出]]></description>
			<content:encoded><![CDATA[<p>终于，经历重重磨难，与9月15日晚将框架的主要功能调试通过，下面简单介绍下这个框架。</p>
<p>运行环境：<br />
Apache2 or later (需要mod_rewrite)<br />
PHP5 or later</p>
<p>下载地址：[<span style="color: #ff0000;">0.1.1-alpha</span> <a href="http://www.nixiaofeng.com/wp-content/uploads/2011/09/fw_0.1.1-alpha.zip">Download</a>]<br />
<strong>0.1.1-alpha是开发版，部分功能尚未完成，所有功能都未经过详细Debug，不能用于生产环境</strong></p>
<p>主要功能：<br />
1. 构建清晰的URL地址<br />
2. 支持多种数据库（目前仅支持Mysql，更多的数据库支持会在将来提供）<br />
3. 内建Memcache支持<br />
4. 如果服务器不支持Memcache，内建HardDisk Cache 临时代替 Memcache<br />
5. 模板化前端HTML（借用Smarty）</p>
<p>接着要做的工作：<br />
1. 构建oracle数据库支持<br />
2. 将Memcache从数据库剥离（目前和数据库封装在一起）<br />
3. 重新整理调用关系，使逻辑上更加清晰<br />
4. 内建各种支持库文件，方便使用</p>
<p>能想到的就是这些，源码稍后放出</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nixiaofeng.com/576.html/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Memory Cache</title>
		<link>http://www.nixiaofeng.com/554.html</link>
		<comments>http://www.nixiaofeng.com/554.html#comments</comments>
		<pubDate>Tue, 06 Sep 2011 08:13:13 +0000</pubDate>
		<dc:creator>LaoNi</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[Web Server]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[memcache]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.nixiaofeng.com/?p=554</guid>
		<description><![CDATA[Memory Cache &#8212; 使用内存作为数据的缓冲，加快数据的读取，减少DB服务器的负担。 在无数的大型网站中，Memory Cache起着至关重要的作用，往往这些大型网站会用上百台Memory Cache服务器。 而在中小型的项目中，适当使用Memory Cache（性能与成本之间的妥协）也是非常有必要的。 之前写过一篇文章《自己动手，写一个简单PHP框架 (番外2)》，介绍了Adodb在查询数据时使用HD作为缓冲，虽然这样也能对性能起到一定提升作用，但会使磁盘I/O增加，磁盘的性能往往随着I/O递增呈现指数级下降，所以在有条件的情况下使用Memory Cache是明智之举。 1. 安装第三方软件库 wget http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-0.5.2-2.rf.src.rpm rpm -ivh rpmforge-release-0.5.2-2.rf.src.rpm 2. 查找Memcached yum search memcached 3. 安装Memcached yum -y install memcached 4. 验证安装 memcached -h 应该会输出一些帮助信息 5. 将memcache加入启动列表 chkconfig &#8211;level 2345 memcached on 6. 配置Memcache vi /etc/sysconfig/memcached 文件中内容如下 PORT=&#8221;11211&#8243; 端口 USER=&#8221;root&#8221; … <a href="http://www.nixiaofeng.com/554.html"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
			<content:encoded><![CDATA[<p>Memory Cache &#8212; 使用内存作为数据的缓冲，加快数据的读取，减少DB服务器的负担。<br />
在无数的大型网站中，Memory Cache起着至关重要的作用，往往这些大型网站会用上百台Memory Cache服务器。<br />
而在中小型的项目中，适当使用Memory Cache（性能与成本之间的妥协）也是非常有必要的。</p>
<p>之前写过一篇文章《<a href="http://www.nixiaofeng.com/484.html" target="_blank">自己动手，写一个简单PHP框架 (番外2)</a>》，介绍了Adodb在查询数据时使用HD作为缓冲，虽然这样也能对性能起到一定提升作用，但会使磁盘I/O增加，磁盘的性能往往随着I/O递增呈现指数级下降，所以在有条件的情况下使用Memory Cache是明智之举。</p>
<p><span id="more-554"></span></p>
<h4>1. 安装第三方软件库</h4>
<p>wget http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-0.5.2-2.rf.src.rpm<br />
rpm -ivh rpmforge-release-0.5.2-2.rf.src.rpm</p>
<h4>2. 查找Memcached</h4>
<p>yum search memcached</p>
<h4>3. 安装Memcached</h4>
<p>yum -y install memcached</p>
<h4>4. 验证安装</h4>
<p>memcached -h<br />
应该会输出一些帮助信息</p>
<h4>5. 将memcache加入启动列表</h4>
<p>chkconfig &#8211;level 2345 memcached on</p>
<h4>6. 配置Memcache</h4>
<p>vi /etc/sysconfig/memcached<br />
文件中内容如下<br />
PORT=&#8221;11211&#8243; 端口<br />
USER=&#8221;root&#8221; 使用的用户名<br />
MAXCONN=&#8221;1024&#8243; 同时最大连接数<br />
CACHESIZE=&#8221;64&#8243; 使用的内存大小<br />
OPTIONS=&#8221;" 附加参数</p>
<h4>7. 查看memcache状态</h4>
<p>memcached-tool [Memcache Server IP]:[Memcache Server Port] stats<br />
如：memcached-tool 127.0.0.1:11211 stats</p>
<p>=====至此，我们将Memcache服务配置完毕，接着我们配置PHP的扩展，以便在程序中来调用=====</p>
<p>PHP共有2种Memcache扩展，一个叫Memcache（2002年发布），另一个叫Memcached（2008年发布）<br />
Memcache<strong>d</strong>比较新，它依赖于limemcached库才能运行，不过它能完成基于Memcache服务的几乎所有功能，比如：Memcached::getResultCode ，它能返回上一次操作Memcache的结果，而Memcache则没有这个功能<br />
Memcache（没有d）不依赖任何库就能运行，安装相对简单，同时也能完成Memcache服务的大部分主要功能。<br />
下面分别介绍2者的安装方式。</p>
<h4>8. 安装PHP的Memcache扩展</h4>
<p>wget http://pecl.php.net/get/memcache-2.2.6.tgz<br />
tar vxzf memcache-2.2.6.tgz<br />
cd memcache-2.2.6<br />
/usr/bin/phpize （如果不知道phpize在什么位置，可以用find / -name phpize查找）<br />
./configure &#8211;enable-memcache &#8211;with-php-config=/usr/bin/php-config &#8211;with-zlib-dir<br />
make<br />
make install<br />
记录下安装成功后的提示，类似于：<br />
Installing shared extensions:     /usr/lib/php/modules/<br />
把这个地址记录下来</p>
<p><strong>增加扩展extension配置文件</strong><br />
查看是否存在 /etc/php.d/memcache.ini 这个文件，如果不存在，我们就自己建立一个<br />
vi /etc/php.d/memcache.ini<br />
增加1行<br />
extension=memcache.so</p>
<p><strong>最后验证一下是否安装完成</strong><br />
php -m|grep memcache<br />
应该会显示memcache<br />
如果出现类似的错误：PHP Warning: Module &#8216;memcache&#8217; already loaded in Unknown on line 0<br />
那可以把php.ini新增加的extension=/usr/lib/php/modules/memcache.so注释掉</p>
<h4>9. PHP的Memcached扩展安装</h4>
<p><strong>首先确认一下json头文件是否正确配置</strong><br />
ls /usr/include/php/ext/json/php_json.h  (这是默认路径，如果安装php是指定了其他路径，则查看其他路径)<br />
如果文件不存在，那我们需要先配置json头文件；如果已经存在，那就不需要下面这步操作了</p>
<p>确认一下json的版本，我们在phpinfo()中可以查看，<br />
wget wget http://pecl.php.net/get/json-1.2.1.tgz  (确认下载了正确的版本)<br />
tar xzvf json-1.2.1.tgz<br />
mkdir -R /usr/include/php/ext/json/<br />
cp json-1.2.1/php_json.h /usr/include/php/ext/json/</p>
<p><strong>安装libmemached</strong><br />
wget http://launchpad.net/libmemcached/1.0/0.50a/+download/libmemcached-0.50.tar.gz  （不要下载0.51版，它无法完成编译）<br />
tar -xzvf libmemcached-0.50.tar.gz<br />
cd libmemcached-0.50.tar.gz<br />
./configure &#8211;prefix=/usr/local/libmemcached  &#8211;with-memcached<br />
make<br />
make install</p>
<p><strong>再安装Memcached扩展</strong><br />
wget http://pecl.php.net/get/memcached-1.0.2.tgz<br />
tar xzvf memcached-1.0.2.tgz<br />
cd memcached-1.0.2<br />
./configure &#8211;enable-memcached &#8211;with-php-config=/usr/bin/php-config &#8211;with-zlib-dir &#8211;with-libmemcached-dir=/usr/local/libmemcached &#8211;prefix=/usr/local/phpmemcached<br />
make<br />
make install<br />
记录下安装成功后的提示，类似于：<br />
Installing shared extensions:     /usr/lib/php/modules/</p>
<p><strong>增加扩展extension配置文件</strong><br />
vi /etc/php.d/memcached.ini<br />
增加1行<br />
extension=memcached.so</p>
<p><strong>最后验证一下是否安装完成</strong><br />
php -m|grep memcached<br />
应该会显示memcached</p>
<p>如果在添加扩展so文件时，直接修改php.ini，那么可能会出现下面的错误：<br />
/usr/lib/php/modules/memcached.so: undefined symbol: php_json_encode in Unknown on line 0<br />
这个错误是因为在 memcached.so 加载之前必须加载 json.so ，而json.so是在/etc/php.d/json.ini中加载，这样会导致json.so在memcached.so之后加载；可以删除/etc/php.d/json.ini文件，而在php.ini中直接添加extensino=json.so来解决</p>
<p>=====PHP中配置MemCache就是这些======</p>
<h4>10. 配置selinux</h4>
<p>selinux是一套linux的安全系统，它指定了应用程序可以访问的磁盘文件、网络端口等等。<br />
如果装有selinux，那么默认的selinux会阻止memcache程序访问11211端口，所以必须对selinux进行配置才行。<br />
方法1： 临时降低selinux运行级别，以便我们进行测试<br />
命令：setenforce [Enforcing | Permissive]<br />
Enforcing表示不允许违反策略的操作<br />
Permissive表示允许违反策略的操作，但会记录下来<br />
我们使用 setenforce Permissive</p>
<p>方法2： 修改selinux配置文件，关闭selinux<br />
编辑 /etc/selinux/config 文件，将 SELINUX=enforcing 改为 SELINUX=disabled</p>
<p>方法3： 修改selinux的http策略，使得httpd进程可以访问网络，这样也就可以使用memcache了<br />
命令：setsebool -P httpd_can_network_connect true<br />
参数P的意思是保持设置的有效性，这样在重启之后这个设置依然有效，不会改变</p>
<h4>11. 查看selinux状态</h4>
<p>sestatus -bv</p>
<h4>12. 配置防火墙</h4>
<p>如果Memcache和Web服务器不是同一台服务器，那么或许还需要配置iptables<br />
登录Memcache服务器，并取得root权限<br />
vi /etc/sysconfig/iptables<br />
-A RH-Firewall-1-INPUT -p tcp -s Web服务器1的IP地址 &#8211;dport 11211 -j ACCEPT<br />
-A RH-Firewall-1-INPUT -p tcp -s Web服务器2的IP地址 &#8211;dport 11211 -j ACCEPT<br />
&#8230;&#8230;<br />
:wq<br />
/etc/init.d/iptables restart</p>
<h4>附：在Windows开发环境中，也能使用Memcached</h4>
<p>1. 到 http://splinedancer.com/memcached-win32/ 下载memcache，如果无法打开链接，可在本文最后下载；<br />
2. 解压后在运行框内执行以下命令：<br />
e:\memcached\memcached.exe -d install<br />
e:\memcached\memcached.exe -d start<br />
3. 然后将 php_memcache.dll（在本文最后下载） 复制到 system32 和 PHP安装目录下的ext文件夹内；<br />
4. 在php.ini文件中增加 extension=php_memcache.dll；<br />
5. 重启Apache</p>
<p>以上是Memcache扩展在Windows中的安装！<br />
我无法找到Memcached扩展在windows如何安装，如果你知道，请告知，谢谢！！！<br />
<a href="http://www.nixiaofeng.com/wp-content/uploads/memcached.7z" target="_blank">下载：Memcached for Windows</a><br />
<a href="http://www.nixiaofeng.com/wp-content/uploads/php_memcache.dll.7z" target="_blank">下载：php_memcache.dll</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nixiaofeng.com/554.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>自己动手，写一个简单PHP框架(8)</title>
		<link>http://www.nixiaofeng.com/547.html</link>
		<comments>http://www.nixiaofeng.com/547.html#comments</comments>
		<pubDate>Mon, 05 Sep 2011 10:22:46 +0000</pubDate>
		<dc:creator>LaoNi</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[session]]></category>

		<guid isPermaLink="false">http://www.nixiaofeng.com/?p=547</guid>
		<description><![CDATA[封装Session 对Session的封装较为简单，暂时不考虑Session跨域时的处理，因为Session跨域有多种解决方案，具体使用哪一种，也要取决于对服务器的权限有多大，在Beta版中，我会封装一个使用数据库解决Session跨子域的问题 Session中我们常用到添加、删除、取值等操作，我们就先封装这些常用的操作 class Session { /** * * Session是否已经启动 * @var Boolean */ private $started = false; /** * * Session * @var Array */ private $session = array (); /** * * 构造函数 */ public function __construct() { $configs = Config::getConfig ( 'session' ); foreach ( $configs as … <a href="http://www.nixiaofeng.com/547.html"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
			<content:encoded><![CDATA[<h2 style="text-align: center;">封装Session</h2>
<p>对Session的封装较为简单，暂时不考虑Session跨域时的处理，因为Session跨域有多种解决方案，具体使用哪一种，也要取决于对服务器的权限有多大，在Beta版中，我会封装一个使用数据库解决Session跨<strong>子域</strong>的问题<br />
Session中我们常用到添加、删除、取值等操作，我们就先封装这些常用的操作</p>
<p><span id="more-547"></span></p>
<pre class="brush: php">
class Session {

	/**
	 *
	 * Session是否已经启动
	 * @var Boolean
	 */
	private $started = false;

	/**
	 *
	 * Session
	 * @var Array
	 */
	private $session = array ();

	/**
	 *
	 * 构造函数
	 */
	public function __construct() {
		$configs = Config::getConfig ( 'session' );
		foreach ( $configs as $key => $val ) {
			ini_set ( 'session.' . $key, $val );
		}
	}

	/**
	 *
	 * 启动Session
	 */
	private function start() {
		if ($this->started) {
			return false;
		}

		@session_start ();
		$this->started = true;

		$this->session = &#038; $_SESSION;
		return true;
	}

	/**
	 *
	 * 获取Session值
	 * @param String $key
	 */
	public function get($key = null) {
		$this->start ();

		if ($key == null) {
			return $this->session;
		} elseif (isset ( $this->session [$key] )) {
			return $this->session [$key];
		} else {
			return false;
		}
	}

	/**
	 *
	 * 设置Session值
	 * @param String $key
	 * @param String $val
	 */
	public function set($key=null, $val=null) {
		if ($key == null || $val == null) return false;
		$this->start ();
		$this->session [$key] = $val;
	}

	/**
	 *
	 * 删除Session值
	 * @param String $key
	 */
	public function del($key) {
		$this->start ();
		if (isset ( $this->session [$key] )) {
			unset ( $this->session [$key] );
		}
	}

	/**
	 *
	 * 判断是否存在Session键值
	 * @param String $key
	 */
	public function has($key) {
		$this->start ();
		if (isset ( $this->session [$key] )) {
			return true;
		}
		return false;
	}

	/**
	 *
	 * 销毁当前Session
	 */
	public function disroty() {
		$this->start ();
		$this->session = array ();
		session_destroy ();
	}

}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.nixiaofeng.com/547.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>自己动手，写一个简单PHP框架 (7)</title>
		<link>http://www.nixiaofeng.com/537.html</link>
		<comments>http://www.nixiaofeng.com/537.html#comments</comments>
		<pubDate>Wed, 31 Aug 2011 07:29:45 +0000</pubDate>
		<dc:creator>LaoNi</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.nixiaofeng.com/?p=537</guid>
		<description><![CDATA[封装Request对象 Request对象的作用是接收页面的参数，并将数据传递给View。 Request是一个数据的接收者，也是发送者。 接收数据主要是从$_POST、$_GET、$_COOKIE中取得数据；而发送数据至View主要是传递Smarty变量、设置Cookie值等操作。 还记得在《自己动手，写一个简单PHP框架 (番外1)》中提到过，我们将URL地址进行了Rewrite， 现在的地址式样是：http://domain/[module]/[action]/[addparams] 注意最后的addparams是页面上通过GET方式传递的参数，我们需要对这部分参数进行格式的规定 附加参数的格式为：name1-value1/name2-value2/name3-value3/&#8230;&#8230; 同时，首页不接受附加参数 注意：参数使用 “-” 行进分割，因此参数名和参数值中都不能再带有 “-” 这个符号；当然，你可以修改配置文件，改成一个比较生僻的字符。 define ( 'GET', 1 ); define ( 'POST', 10 ); define ( 'COOKIE', 100 ); class Request { /** * * 传入方法 * @var String */ private $method; /** * * 传入值 * @var Array … <a href="http://www.nixiaofeng.com/537.html"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
			<content:encoded><![CDATA[<h2 style="text-align: center;">封装Request对象</h2>
<p>Request对象的作用是接收页面的参数，并将数据传递给View。<br />
Request是一个数据的接收者，也是发送者。<br />
接收数据主要是从$_POST、$_GET、$_COOKIE中取得数据；而发送数据至View主要是传递Smarty变量、设置Cookie值等操作。</p>
<p>还记得在《<a href="http://www.nixiaofeng.com/467.html" target="_blank">自己动手，写一个简单PHP框架 (番外1)</a>》中提到过，我们将URL地址进行了Rewrite，<br />
现在的地址式样是：http://domain/[module]/[action]/[addparams]<br />
注意最后的addparams是页面上通过GET方式传递的参数，我们需要对这部分参数进行格式的规定</p>
<p><span id="more-537"></span><br />
附加参数的格式为：name1-value1/name2-value2/name3-value3/&#8230;&#8230;<br />
同时，首页不接受附加参数<br />
注意：参数使用 “-” 行进分割，因此参数名和参数值中都不能再带有 “-” 这个符号；当然，你可以修改配置文件，改成一个比较生僻的字符。</p>
<pre class="brush: php">
define ( 'GET', 1 );
define ( 'POST', 10 );
define ( 'COOKIE', 100 );

class Request {

    /**
     *
     * 传入方法
     * @var String
     */
    private $method;

    /**
     *
     * 传入值
     * @var Array
     */
    private $params = array ();

    /**
     *
     * Smarty对象实例
     * @var unknown_type
     */
    private $_smarty;

    /**
     *
     * 构造函数
     */
    public function __construct(&#038;$smarty) {

        // 根据PHP Magic Quotes设定，删除多余的斜杠
        if (get_magic_quotes_gpc ()) {
            $in = array (&#038;$_GET, &#038;$_POST, &#038;$_COOKIE, &#038;$_FILES );
            while ( (list ( $k, $v ) = each ( $in )) !== false ) {
                foreach ( $v as $key => $val ) {
                    if (! is_array ( $val )) {
                        $in [$k] [$key] = stripslashes ( $val );
                        continue;
                    }
                    $in [] = &#038; $in [$k] [$key];
                }
            }
            unset ( $in );
        }

        // 设定提交方法
        $request_method = $_SERVER ['REQUEST_METHOD'];
        if (defined ( $request_method )) {
            $this->method = $request_method;
        } else {
            $this->method = null;
        }

        $this->_smarty = $smarty;
    }

    /**
     *
     * 获取传递到页面的参数值
     * @param String $method
     */
    public function setRequestMethod($method) {
        $configs = Config::getConfig('request');

        if (($method &#038; GET) == GET)
            $this->appendParam ( $_GET );
            $addparams = isset($_GET['params']) ? $_GET['params'] : '';
            $group = explode('/', $addparams);
            foreach ($group as $key=>$val) {
                $p = explode($configs['addparamseparator'], $val);
                if (count($p) == 2) {
                    $pp = array($p[0] => $p[1]);
                    $this->appendParam ( $pp );
                }
            }
        if (($method &#038; POST) == POST)
            $this->appendParam ( $_POST );
        if (($method &#038; COOKIE) == COOKIE)
            $this->appendParam ( $_COOKIE );

        $this->appendParam ( $_FILES );
    }

    /**
     *
     * 添加传入的参数
     * @param unknown_type $array
     */
    private function appendParam(&#038; $array) {
        $this->params = array_merge ( $this->params, $array );
    }

    /**
     *
     * 获取页面使用的提交方式
     */
    public function getMethod() {
        return $this->method;
    }

    /**
     *
     * 获取指定的参数
     * @param String $name
     */
    public function getAttribute($name = null) {
        if ($name == null) {
            return $this->params;
        } else if (isset ( $this->params [$name] )) {
            return $this->params [$name];
        } else {
            return null;
        }
    }

    /**
     *
     * 将值传递给Smarty
     * @param String $name    模板中使用的变量名
     * @param String $value    变量的值
     */
    public function setAttribute($name, $value) {
        $this->_smarty->assign ( $name, $value );
    }

    /**
     *
     * 获取上传的文件
     * @param String $fileName
     */
    public function getFile($fileName=null) {
        if ($fileName == null) return false;
        if (isset($this->params[$fileName])) {
            return $this->params[$fileName];
        } else {
            return false;
        }
    }

    /**
     *
     * 移动上传的文件到指定目录
     * @param String $filename
     * @param String $distination
     */
    public function uploadFile($filename, $destination) {
        $file = self::getFile($filename);

        if (is_uploaded_file($filename)) {
            return move_uploaded_file($filename, $destination);
        } else {
            return false;
        }
    }

    /**
     *
     * 设置Cookie
     * @param String $name
     * @param String $value
     * @param Integer $expire
     * @param String $path
     * @param String $domain
     */
    public function setCookie ($name, $value, $expire=null, $path=null, $domain=null) {
        $config = Config::getConfig('cookie');
        $expire = is_null($expire) ? time()+$config['expire']*86400 : time()+$expire*68400;
        $path = is_null($path) ? $config['path'] : $path;
        $domain = is_null($domain) ? $config['domain'] : $domain;
        setcookie($name, $value, $expire, $path, $domain);
    }

    /**
     *
     * 获取Cookie
     * @param String $name
     */
    public function getCookie ($name) {
        if (isset($this->params[$name])) return $this->params[$name];
        else return false;
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.nixiaofeng.com/537.html/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

