<?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>EaseMarry Blogs &#187; PHP Development</title>
	<atom:link href="http://www.easemarry.com/blog/category/php/php-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.easemarry.com/blog</link>
	<description>php and java code</description>
	<lastBuildDate>Sun, 09 Aug 2009 16:09:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.3</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Generate the Guid use for php class</title>
		<link>http://www.easemarry.com/blog/generate-the-guid-use-for-php-class/</link>
		<comments>http://www.easemarry.com/blog/generate-the-guid-use-for-php-class/#comments</comments>
		<pubDate>Mon, 13 Apr 2009 16:42:17 +0000</pubDate>
		<dc:creator>rueben</dc:creator>
				<category><![CDATA[PHP Code]]></category>
		<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[Currenttimemillis]]></category>
		<category><![CDATA[Guid]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Random Function]]></category>
		<category><![CDATA[Return Address]]></category>
		<category><![CDATA[Server Addr]]></category>
		<category><![CDATA[Tmp]]></category>

		<guid isPermaLink="false">http://www.easemarry.com/blog/?p=43</guid>
		<description><![CDATA[
?View Code PHP1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
&#60; ?php
class   System
&#123;
	function   currentTimeMillis&#40;&#41;
	&#123;
		list&#40;$usec,   $sec&#41;   =   explode&#40;&#34;   &#34;,microtime&#40;&#41;&#41;;
		return   $sec.substr&#40;$usec,   2,   3&#41;;
	&#125;
&#125;
class   NetAddress
&#123;
	var   $Name   = 'easemarry.com';
	var   $IP   = '69.65.10.199';
	function   getLocalHost&#40;&#41;   //  [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p43code2'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p432"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
</pre></td><td class="code" id="p43code2"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php
<span style="color: #000000; font-weight: bold;">class</span>   <a href="http://www.php.net/system"><span style="color: #990000;">System</span></a>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">function</span>   currentTimeMillis<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<a href="http://www.php.net/list"><span style="color: #990000;">list</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$usec</span><span style="color: #339933;">,</span>   <span style="color: #000088;">$sec</span><span style="color: #009900;">&#41;</span>   <span style="color: #339933;">=</span>   <a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;   &quot;</span><span style="color: #339933;">,</span><a href="http://www.php.net/microtime"><span style="color: #990000;">microtime</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span>   <span style="color: #000088;">$sec</span><span style="color: #339933;">.</span><a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$usec</span><span style="color: #339933;">,</span>   <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span>   <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">class</span>   NetAddress
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span>   <span style="color: #000088;">$Name</span>   <span style="color: #339933;">=</span> <span style="color: #0000ff;">'easemarry.com'</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">var</span>   <span style="color: #000088;">$IP</span>   <span style="color: #339933;">=</span> <span style="color: #0000ff;">'69.65.10.199'</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">function</span>   getLocalHost<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>   <span style="color: #666666; font-style: italic;">//   static</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$address</span>   <span style="color: #339933;">=</span>   <span style="color: #000000; font-weight: bold;">new</span>   NetAddress<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$address</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Name</span>   <span style="color: #339933;">=</span>   <span style="color: #000088;">$_ENV</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;COMPUTERNAME&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$address</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">IP</span>   <span style="color: #339933;">=</span>   <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;SERVER_ADDR&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span>   <span style="color: #000088;">$address</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">function</span>   toString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span>   <a href="http://www.php.net/strtolower"><span style="color: #990000;">strtolower</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">IP</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">class</span>   Random
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">function</span>   nextLong<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$tmp</span>   <span style="color: #339933;">=</span>   <a href="http://www.php.net/rand"><span style="color: #990000;">rand</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>?<span style="color: #0000ff;">'-'</span><span style="color: #339933;">:</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span>   <span style="color: #000088;">$tmp</span><span style="color: #339933;">.</span><a href="http://www.php.net/rand"><span style="color: #990000;">rand</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1000</span><span style="color: #339933;">,</span>   <span style="color: #cc66cc;">9999</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><a href="http://www.php.net/rand"><span style="color: #990000;">rand</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1000</span><span style="color: #339933;">,</span>   <span style="color: #cc66cc;">9999</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><a href="http://www.php.net/rand"><span style="color: #990000;">rand</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1000</span><span style="color: #339933;">,</span>   <span style="color: #cc66cc;">9999</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><a href="http://www.php.net/rand"><span style="color: #990000;">rand</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #339933;">,</span>   <span style="color: #cc66cc;">999</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><a href="http://www.php.net/rand"><span style="color: #990000;">rand</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #339933;">,</span>   <span style="color: #cc66cc;">999</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span>   Guid
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span>   <span style="color: #000088;">$valueBeforeMD5</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">var</span>   <span style="color: #000088;">$valueAfterMD5</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">function</span>   Guid<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getGuid</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #666666; font-style: italic;">//</span>
	<span style="color: #000000; font-weight: bold;">function</span>   getGuid<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$address</span>   <span style="color: #339933;">=</span>   NetAddress<span style="color: #339933;">::</span><span style="color: #004000;">getLocalHost</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">valueBeforeMD5</span>   <span style="color: #339933;">=</span>   <span style="color: #000088;">$address</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">':'</span><span style="color: #339933;">.</span><a href="http://www.php.net/system"><span style="color: #990000;">System</span></a><span style="color: #339933;">::</span><span style="color: #004000;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">':'</span><span style="color: #339933;">.</span>Random<span style="color: #339933;">::</span><span style="color: #004000;">nextLong</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">valueAfterMD5</span>   <span style="color: #339933;">=</span>   <a href="http://www.php.net/md5"><span style="color: #990000;">md5</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">valueBeforeMD5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">function</span>   newGuid<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$Guid</span>   <span style="color: #339933;">=</span>   <span style="color: #000000; font-weight: bold;">new</span>   Guid<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span>   <span style="color: #000088;">$Guid</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">function</span>   toString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$raw</span>   <span style="color: #339933;">=</span>   <a href="http://www.php.net/strtoupper"><span style="color: #990000;">strtoupper</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">valueAfterMD5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span>   <a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$raw</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'_'</span><span style="color: #339933;">.</span><a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$raw</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">8</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'_'</span><span style="color: #339933;">.</span><a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$raw</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">12</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'_'</span><span style="color: #339933;">.</span><a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$raw</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">16</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'_'</span><span style="color: #339933;">.</span><a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$raw</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">20</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'_'</span><span style="color: #339933;">.</span><a href="http://www.php.net/time"><span style="color: #990000;">time</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.easemarry.com/blog/generate-the-guid-use-for-php-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using sockets in PHP : Get articles from Usenet</title>
		<link>http://www.easemarry.com/blog/using-sockets-in-php-get-articles-from-usenet/</link>
		<comments>http://www.easemarry.com/blog/using-sockets-in-php-get-articles-from-usenet/#comments</comments>
		<pubDate>Fri, 23 May 2008 16:53:11 +0000</pubDate>
		<dc:creator>rueben</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Code]]></category>
		<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[Connect System]]></category>
		<category><![CDATA[Domain Name]]></category>
		<category><![CDATA[Internet Domain]]></category>
		<category><![CDATA[Ip Address]]></category>
		<category><![CDATA[Local Hosts]]></category>
		<category><![CDATA[Network News Transfer Protocol]]></category>
		<category><![CDATA[Protocols]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[Socket Connection]]></category>
		<category><![CDATA[Socket Port]]></category>
		<category><![CDATA[Sockets]]></category>
		<category><![CDATA[Tcp Socket]]></category>
		<category><![CDATA[Udp Connections]]></category>
		<category><![CDATA[Unsuccessful Attempt]]></category>

		<guid isPermaLink="false">http://www.easemarry.com/blog/using-sockets-in-php-get-articles-from-usenet/</guid>
		<description><![CDATA[http://www.phpbuilder.net/columns/armel20010427.php3
PHP can open sockets on remote or local hosts. Here is a hands-on example of using such a socket: getting connected to a Usenet News Server, talking to this server, and downloading some articles for a precise newsgroup.
Opening a socket in PHP
Sockets are opened using fsockopen(). This function is both available in PHP3 and PHP4. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.phpbuilder.net/columns/armel20010427.php3">http://www.phpbuilder.net/columns/armel20010427.php3</a></p>
<p>PHP can open sockets on remote or local hosts. Here is a hands-on example of using such a socket: getting connected to a Usenet News Server, talking to this server, and downloading some articles for a precise newsgroup.</p>
<p>Opening a socket in PHP</p>
<p>Sockets are opened using fsockopen(). This function is both available in PHP3 and PHP4. It uses the following prototype :</p>
<p><font color="#0000bb">&lt;?php<br />
int fsockopen<br />
    </font><font color="#007700">(</font><font color="#0000bb">string hostname</font><font color="#007700">,<br />
        </font><font color="#0000bb">int port </font><font color="#007700">[,<br />
        </font><font color="#0000bb">int errno </font><font color="#007700">[,<br />
        </font><font color="#0000bb">string errstr </font><font color="#007700">[,<br />
        </font><font color="#0000bb">double timeout</font><font size="2" color="#007700" face="Courier">]]])<br />
</font><font size="2" face="Courier">?&gt;</font></p>
<p> For the Internet domain, it will open a TCP socket connection to hostname on port port. hostname may in this case be either a fully qualified domain name or an IP address. For UDP connections, you need to explicitly specify the protocol: udp://hostname. For the Unix domain, hostname will be used as the path to the socket, port must be set to 0 in this case. The optional timeout can be used to set a timeout in seconds for the connect system call.</p>
<p>More information about fsockopen() : <a href="http://www.php.net/manual/function.fsockopen.php">http://www.php.net/manual/function.fsockopen.php</a></p>
<p>Network News Transfer Protocol</p>
<p>Accessing a Usenet News Server requires using a specific protocol, called NNTP and standing for Network News Transfer Protocol.</p>
<p>This protocol is higly detailed in RFC977 (Request For Comment number 977), which is available at : <a href="http://www.w3.org/Protocols/rfc977/rfc977.html">http://www.w3.org/Protocols/rfc977/rfc977.html</a></p>
<p>This document described precisely how to connect to and then dialog with the NNTP server thanks to the various commands available for the task.</p>
<p>Connecting</p>
<p>Connecting to the NNTP server requires knowing its hostname (or IP address) and the port it is listening on. You should include a timeout so that an unsuccessful attempt at connecting does not &#8220;freeze&#8221; the application.<br />
<font color="#0000bb">&lt;?php<br />
$cfgServer    </font><font color="#007700">= </font><font color="#dd0000">&#8220;your.news.host&#8221;</font><font color="#007700">;<br />
</font><font color="#0000bb">$cfgPort    </font><font color="#007700">= </font><font color="#0000bb">119</font><font color="#007700">;<br />
</font><font color="#0000bb">$cfgTimeOut    </font><font color="#007700">= </font><font color="#0000bb">10</font><font size="2" color="#007700" face="Courier">;</font><font size="2" color="#007700" face="Courier"></font><font color="#ff8000">// open a socket<br />
</font><font color="#007700">if(!</font><font color="#0000bb">$cfgTimeOut</font><font size="2" color="#007700" face="Courier">)<br />
    </font><font color="#ff8000">// without timeout<br />
    </font><font color="#0000bb">$usenet_handle </font><font color="#007700">= </font><font color="#0000bb">fsockopen</font><font color="#007700">(</font><font color="#0000bb">$cfgServer</font><font color="#007700">, </font><font color="#0000bb">$cfgPort</font><font size="2" color="#007700" face="Courier">);<br />
else<br />
    </font><font color="#ff8000">// with timeout<br />
    </font><font color="#0000bb">$usenet_handle </font><font color="#007700">= </font><font color="#0000bb">fsockopen</font><font color="#007700">(</font><font color="#0000bb">$cfgServer</font><font color="#007700">, </font><font color="#0000bb">$cfgPort</font><font color="#007700">, &amp;</font><font color="#0000bb">$errno</font><font color="#007700">, &amp;</font><font color="#0000bb">$errstr</font><font color="#007700">, </font><font color="#0000bb">$cfgTimeOut</font><font color="#007700">);if(!</font></p>
<p><font color="#0000bb">$usenet_handle</font><font color="#007700">) {<br />
    echo </font><font color="#dd0000">&#8220;Connexion failed\n&#8221;</font><font color="#007700">;<br />
    exit();<br />
}    <br />
else {<br />
    echo </font><font color="#dd0000">&#8220;Connected\n&#8221;</font><font color="#007700">;<br />
    </font><font color="#0000bb">$tmp </font><font color="#007700">= </font><font color="#0000bb">fgets</font><font color="#007700">(</font><font color="#0000bb">$usenet_handle</font><font color="#007700">, </font><font color="#0000bb">1024</font><font size="2" color="#007700" face="Courier">);<br />
}</font><font size="2" color="#007700" face="Courier"></font><font size="2" face="Courier">?&gt;</font><br />
Talking to the Server</p>
<p>We are now connected to the server, and can talk to it through th previously opened socket. Let us say we want to get the 10 latest articles from some newsgroup. RFC977 specifies that the first step is to select the right newsgroup with the GROUP command :</p>
<p>GROUP ggg</p>
<p>The required parameter ggg is the name of the newsgroup to be selected (e.g. &#8220;net.news&#8221;). A list of valid newsgroups may be obtained from the LIST command. The successful selection response will return the article numbers of the first and last articles in the group, and an estimate of the number of articles on file in the group.</p>
<p>Example:</p>
<p>chrome:~$ telnet my.news.host 119<br />
Trying aa.bb.cc.dd&#8230;<br />
Connected to my.news.host.<br />
Escape character is &#8216;^]&#8217;.<br />
200 my.news.host InterNetNews NNRP server INN 2.2.2 13-Dec-1999 ready (posting ok).<br />
GROUP alt.test<br />
211 232 222996 223235 alt.test<br />
quit<br />
205<br />
After receiving the command &#8221; GROUP alt.test&#8221;, the News Server answered &#8220;211 232 222996 223235 alt.test&#8221;. 211 is an RFC defined code (basically saying the command was succesfully executed &#8211; check the RFC for more details). It also answered it currently has 232 articles, indexed 222996 for the oldest through 223235 for the latest. These are called article numbers. Now, let us have a count here : 222996 + 232 by no means equals to 232235. The seven missing articles were removed one way or another from the server, either cancelled by their legitimate author (yes, it is possible and easy to do !) or deleted after report of abuse for example.<br />
Be careful though, the server might require authentication before selecting the newsgroup, depending on wether it is a public or private server. It could also let anybody retrieve articles but require authentication to publish an article.</p>
<p><font size="2" color="#0000bb" face="Courier">&lt;?php</font><font size="2" color="#0000bb" face="Courier"></font><font color="#ff8000">//$cfgUser    = &#8220;xxxxxx&#8221;;<br />
//$cfgPasswd    = &#8220;yyyyyy&#8221;;<br />
</font><font color="#0000bb">$cfgNewsGroup    </font><font color="#007700">= </font><font color="#dd0000">&#8220;alt.php&#8221;</font><font size="2" color="#007700" face="Courier">;</font></p>
<p><font color="#ff8000">// identification required on private server<br />
</font><font color="#007700">if(</font><font color="#0000bb">$cfgUser</font><font color="#007700">) {<br />
    </font><font color="#0000bb">fputs</font><font color="#007700">(</font><font color="#0000bb">$usenet_handle</font><font color="#007700">, </font><font color="#dd0000">&#8220;AUTHINFO USER &#8220;</font><font color="#007700">.</font><font color="#0000bb">$cfgUser</font><font color="#007700">.</font><font color="#dd0000">&#8220;\n&#8221;</font><font color="#007700">);<br />
    </font><font color="#0000bb">$tmp </font><font color="#007700">= </font><font color="#0000bb">fgets</font><font color="#007700">(</font><font color="#0000bb">$usenet_handle</font><font color="#007700">, </font><font color="#0000bb">1024</font><font color="#007700">);</font><font color="#007700">    </font><font color="#0000bb">fputs</font><font color="#007700">(</font><font color="#0000bb">$usenet_handle</font><font color="#007700">, </font><font color="#dd0000">&#8220;AUTHINFO PASS &#8220;</font><font color="#007700">.</font><font color="#0000bb">$cfgPasswd</font><font color="#007700">.</font><font color="#dd0000">&#8220;\n&#8221;</font><font color="#007700">);<br />
    </font><font color="#0000bb">$tmp </font><font color="#007700">= </font><font color="#0000bb">fgets</font><font color="#007700">(</font><font color="#0000bb">$usenet_handle</font><font color="#007700">, </font><font color="#0000bb">1024</font><font size="2" color="#007700" face="Courier">);    </font></p>
<p><font color="#ff8000">// check error<br />
    <br />
    </font><font color="#007700">if(</font><font color="#0000bb">$tmp </font><font color="#007700">!= </font><font color="#dd0000">&#8220;281 Ok\r\n&#8221;</font><font color="#007700">) {<br />
        echo </font><font color="#dd0000">&#8220;502 Authentication error\n&#8221;</font><font size="2" color="#007700" face="Courier">;<br />
        exit();<br />
    }    <br />
}</font><font size="2" color="#007700" face="Courier"></font><font color="#ff8000">// select newsgroup</font></p>
<p><font color="#0000bb">fputs</font><font color="#007700">(</font><font color="#0000bb">$usenet_handle</font><font color="#007700">, </font><font color="#dd0000">&#8220;GROUP &#8220;</font><font color="#007700">.</font><font color="#0000bb">$cfgNewsGroup</font><font color="#007700">.</font><font color="#dd0000">&#8220;\n&#8221;</font><font color="#007700">);<br />
</font><font color="#0000bb">$tmp </font><font color="#007700">= </font><font color="#0000bb">fgets</font><font color="#007700">(</font><font color="#0000bb">$usenet_handle</font><font color="#007700">, </font><font color="#0000bb">1024</font><font color="#007700">);</font><font color="#007700">if(</font><font color="#0000bb">$tmp </font><font color="#007700">== </font><font color="#dd0000">&#8220;480 Authentication required for command\r\n&#8221;</font><font color="#007700">) {<br />
    echo </font><font color="#dd0000">&#8220;$tmp</font><font color="#007700">\n</font><font color="#dd0000">&#8220;</font><font color="#007700">;<br />
    exit();<br />
}    </font></p>
<p><font color="#0000bb">$info </font><font color="#007700">= </font><font color="#0000bb">split</font><font color="#007700">(</font><font color="#dd0000">&#8221; &#8220;</font><font color="#007700">, </font><font color="#0000bb">$tmp</font><font color="#007700">);<br />
</font><font color="#0000bb">$first </font><font color="#007700">= </font><font color="#0000bb">$info</font><font color="#007700">[</font><font color="#0000bb">2</font><font color="#007700">];<br />
</font><font color="#0000bb">$last </font><font color="#007700">= </font><font color="#0000bb">$info</font><font color="#007700">[</font><font color="#0000bb">3</font><font color="#007700">];</font><font color="#007700"> print </font><font color="#dd0000">&#8220;First : $first</font><font color="#007700">\n</font><font color="#dd0000">&#8220;</font><font color="#007700">;<br />
print </font><font color="#dd0000">&#8220;Last : $last</font><font color="#007700">\n</font><font color="#dd0000">&#8220;</font><font size="2" color="#007700" face="Courier">;</font><font size="2" color="#007700" face="Courier"></font><font size="2" face="Courier">?&gt;</font></p>
]]></content:encoded>
			<wfw:commentRss>http://www.easemarry.com/blog/using-sockets-in-php-get-articles-from-usenet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple PHP Cache Manager Class</title>
		<link>http://www.easemarry.com/blog/simple-php-cache-manager-class/</link>
		<comments>http://www.easemarry.com/blog/simple-php-cache-manager-class/#comments</comments>
		<pubDate>Wed, 19 Mar 2008 03:54:00 +0000</pubDate>
		<dc:creator>rueben</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Code]]></category>
		<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[Arbitrary Data]]></category>
		<category><![CDATA[Cache Data]]></category>
		<category><![CDATA[Cache Files]]></category>
		<category><![CDATA[Cache Manager]]></category>
		<category><![CDATA[Cached Data]]></category>
		<category><![CDATA[Life Time]]></category>
		<category><![CDATA[Php Cache]]></category>
		<category><![CDATA[Root Directory]]></category>

		<guid isPermaLink="false">http://www.easemarry.com/blog/simple-php-cache-manager-class/</guid>
		<description><![CDATA[This class can be used to cache arbitrary data in files.
It can check if the cache with a certain key already exists. If it exists and it is not expired, it can return the cached data. Otherwise it can store newly generated data in a cache file with the given key.
The class can be configured [...]]]></description>
			<content:encoded><![CDATA[<p>This class can be used to cache arbitrary data in files.</p>
<p>It can check if the cache with a certain key already exists. If it exists and it is not expired, it can return the cached data. Otherwise it can store newly generated data in a cache file with the given key.</p>
<p>The class can be configured to set the cache life time and the root directory of where all the cache files will be stored.</p>
<p>cachemanager.php</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p33code5'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p335"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
</pre></td><td class="code" id="p33code5"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php
<span style="color: #000000; font-weight: bold;">class</span> CacheManager <span style="color: #000000; font-weight: bold;">extends</span> Entity <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	* Contains number of seconds - timeframe for storing cache
	* @http://www.easemarry.com/blog
	* @var int
	* @name timeframe
	* @access private
	*/</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$timeframe</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	* Contains name of the cache root directory 
	*
	* @var string
	* @name _cacheRoot
	* @access public
	*/</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$_cacheRoot</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	* Constructor, defines timeframe for storing cache
	*
	* @param int number of seconds
	* @param int number of minutes
	* @param int number of hours
	* @param int number of days
	* @param int number of month
	* @param int number of years
	*/</span>
	<span style="color: #000000; font-weight: bold;">function</span> CacheManager <span style="color: #009900;">&#40;</span><span style="color: #000088;">$second</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$minute</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$hour</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$day</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$month</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$year</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">timeframe</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mktime"><span style="color: #990000;">mktime</span></a> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$hour</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$minute</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$second</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$month</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$day</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1970</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$year</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	* Checks if cache contains file no older than timeframe
	*
	* @return string
	*/</span>
	<span style="color: #000000; font-weight: bold;">function</span> CheckCache <span style="color: #009900;">&#40;</span><span style="color: #000088;">$model</span><span style="color: #339933;">,</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$fname</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$timeframe</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$result</span>   <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$filename</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$fname</span> ? <span style="color: #000088;">$fname</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_cacheRoot<span style="color: #339933;">.</span><a href="http://www.php.net/strtolower"><span style="color: #990000;">strtolower</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$model</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span> ? <span style="color: #000088;">$key</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'model'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'.html'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <a href="http://www.php.net/file_exists"><span style="color: #990000;">file_exists</span></a> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$tframe</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$timeframe</span> ? <span style="color: #000088;">$timeframe</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">timeframe</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/time"><span style="color: #990000;">time</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <a href="http://www.php.net/filemtime"><span style="color: #990000;">filemtime</span></a> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$tframe</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">RetrieveData</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$result</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	* Read the content of the file
	*
	* @param string filename
	* @return string
	*/</span>
	<span style="color: #000000; font-weight: bold;">function</span> RetrieveData <span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$fp</span>      <span style="color: #339933;">=</span> <a href="http://www.php.net/fopen"><span style="color: #990000;">fopen</span></a> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'r'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/fread"><span style="color: #990000;">fread</span></a> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span> <a href="http://www.php.net/filesize"><span style="color: #990000;">filesize</span></a> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<a href="http://www.php.net/fclose"><span style="color: #990000;">fclose</span></a> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	* Store content in the file
	*
	* @return string
	*/</span>
	<span style="color: #000000; font-weight: bold;">function</span> SaveToCache <span style="color: #009900;">&#40;</span><span style="color: #000088;">$model</span><span style="color: #339933;">,</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$fname</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$filename</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$fname</span> ? <span style="color: #000088;">$fname</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_cacheRoot<span style="color: #339933;">.</span><a href="http://www.php.net/strtolower"><span style="color: #990000;">strtolower</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$model</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span> ? <span style="color: #000088;">$key</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'model'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'.html'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$fp</span>       <span style="color: #339933;">=</span> <a href="http://www.php.net/fopen"><span style="color: #990000;">fopen</span></a> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'w+'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<a href="http://www.php.net/fwrite"><span style="color: #990000;">fwrite</span></a> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<a href="http://www.php.net/fclose"><span style="color: #990000;">fclose</span></a> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$filename</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>example.php</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p33code6'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p336"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code" id="p33code6"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php
<span style="color: #009933; font-style: italic;">/**
* This example represents how easily we can automate 
* caching of both news list, and single news using 
* CacheManager class
*/</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> GetElement <span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">/* return single news */</span>
	<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'Full News Number '</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> GetElements <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">/* return news list */</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span><span style="color: #cc66cc;">11</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$result</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;a href=&quot;./?id='</span><span style="color: #339933;">.</span><span style="color: #000088;">$i</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;News '</span><span style="color: #339933;">.</span><span style="color: #000088;">$i</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;br / /&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$result</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">include</span> <span style="color: #0000ff;">'./cachemanager.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$key</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <a href="http://www.php.net/intval"><span style="color: #990000;">intval</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$CacheManager</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">&amp;new</span> CacheManager <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$CacheManager</span><span style="color: #339933;">-&gt;</span>_cacheRoot <span style="color: #339933;">=</span> <span style="color: #0000ff;">'./cache/'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$CacheManager</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CheckCache</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'news'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$key</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;">$content</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span> ? GetElement <span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">GetElements</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$CacheManager</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SaveToCache</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'news'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.easemarry.com/blog/simple-php-cache-manager-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Cookie Handler Class</title>
		<link>http://www.easemarry.com/blog/php-cookie-handler-class/</link>
		<comments>http://www.easemarry.com/blog/php-cookie-handler-class/#comments</comments>
		<pubDate>Wed, 12 Mar 2008 09:51:00 +0000</pubDate>
		<dc:creator>rueben</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Code]]></category>
		<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[Class Source]]></category>
		<category><![CDATA[Cookie Functions]]></category>
		<category><![CDATA[Cookie Value]]></category>
		<category><![CDATA[Delete Cookie]]></category>
		<category><![CDATA[Handler Class]]></category>
		<category><![CDATA[PHP Cookie]]></category>

		<guid isPermaLink="false">http://www.easemarry.com/blog/php-cookie-handler-class/</guid>
		<description><![CDATA[
This class allows for the handling of normal and serialized cookies as well as switching between these types of cookies.
Cookie Functions:
Write Cookies
Read Cookies
Delete Cookies
Use of this class is fairly simple.
Step 1: Include the class source in your php project using the require or include statement.
Step 2: Instance the cookie class by using the new keyword. [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsense#co-2--><br />
This class allows for the handling of normal and serialized cookies as well as switching between these types of cookies.</p>
<p>Cookie Functions:<br />
Write Cookies<br />
Read Cookies<br />
Delete Cookies</p>
<p>Use of this class is fairly simple.</p>
<p>Step 1: Include the class source in your php project using the require or include statement.<br />
Step 2: Instance the cookie class by using the new keyword. The constructor uses these parameters<br />
cookieName[string]{required} as the base name of the cookie<br />
cookieTimeout[int]{required} as the time added the Unix timestamp to determine when a cookie expires<br />
cookieSerialize[bool]{optional} default is false. If set to true then the cookies will be stored as a single serialized cookie.<br />
cookiePath[string]{optional} default is &#8220;/&#8221; for root path you can set for sub-directory paths here if you wish.</p>
<p>The constructor also handles the switch over from individual cookies to serialzied cookies.</p>
<p>Step 3: Write a cookie</p>
<p>NOTE: It is important to remember that writing cookies must be done before any other output is sent to the browser.</p>
<p>The WriteCookie function takes as an array as an argument. This array should be built so that the name of the value name<br />
is stored as the array element index and the value to be set is the element value<br />
array[name] = value</p>
<p>Create one element for each value you want stored as a cookie.</p>
<p>Step 4: Read a cookie</p>
<p>NOTE: Of course you can read a cookie from the $_COOKIE array however you will lose out on the in built handling of serialized cookies.</p>
<p>You read a cookie&#8217;s value by calling the ReadCookie function which takes as its argument the value name and you will receive the<br />
cookie value in return. If the value name is not present (this single cookie is not set or not in the serialized array) then a NULL<br />
is returned.</p>
<p>It is best to store the value to a variable and then test for NULL by the is_null function.</p>
<p>Step 5: KillCookie</p>
<p>The KillCookie function allows you to delete a single cookie item or array element. It takes as its argument the value name to be deleted.</p>
<p>Step 6: DestroyAllCookies</p>
<p>Will go through all the cookies with the base name as set in the constructor and delete them.<br />
The delete process for this and the KillCookie function is handled by setting the cookie&#8217;s expire date as the current Unix timestamp<br />
- a large integer (several years).</p>
<p>Step 7: To change cookies from individual cookies to a serialized cookie<br />
This is handled by changing the constructor&#8217;s cookieSerialize flag from false to true. It must be done when the cookieClass is<br />
instanced or it will not function correctly.</p>
<p>If you have any comments or questions concerning this php class you may contact me at <a href="mailto:jrsofty@gmail.com">jrsofty@gmail.com</a></p>
<p> </p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p31code8'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p318"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
</pre></td><td class="code" id="p31code8"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php
	<span style="color: #666666; font-style: italic;">// cookieClass</span>
	<span style="color: #666666; font-style: italic;">// Copyright (C) 2005 JRSofty Programming.</span>
	<span style="color: #666666; font-style: italic;">// http://jrsofty1.stinkbugonline.com</span>
	<span style="color: #666666; font-style: italic;">// Licensed under GNU/GPL </span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">class</span> cookieClass<span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$cName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$cTime</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$cSerialize</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>		
		<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$cPath</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">function</span> cookieClass<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cookieName</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cookieTimeout</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cookieSerialize</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cookiePath</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cName</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$cookieName</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cTime</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$cookieTimeout</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cSerialize</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$cookieSerialize</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cPath</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$cookiePath</span><span style="color: #339933;">;</span>
			<span style="color: #666666; font-style: italic;">// This should fix the issue if you have cookies set and THEN turn on the serialization.</span>
			<span style="color: #000088;">$iname</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cName</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;_S&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cSerialize</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_COOKIE</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$iname</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$cookArr</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_COOKIE</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$name</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$val</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><a href="http://www.php.net/strpos"><span style="color: #990000;">strpos</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cName</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// make sure it is a cookie set by this application</span>
						<span style="color: #000088;">$subname</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span><a href="http://www.php.net/strlen"><span style="color: #990000;">strlen</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cName</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #000088;">$cookArr</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$subname</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$val</span><span style="color: #339933;">;</span>
						<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">KillCookie</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">WriteCookie</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cookArr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #666666; font-style: italic;">// This is the opposite from above. changes a serialized cookie to multiple cookies without loss of data</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cSerialize</span> <span style="color: #339933;">&amp;&amp;</span> <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_COOKIE</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$iname</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$cookArr</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/unserialize"><span style="color: #990000;">unserialize</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_COOKIE</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$iname</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">KillCookie</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$iname</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">WriteCookie</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cookArr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">function</span> DestroyAllCookies<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_COOKIE</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$name</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$val</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><a href="http://www.php.net/strpos"><span style="color: #990000;">strpos</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cName</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$_COOKIE</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">KillCookie</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">function</span> ReadCookie<span style="color: #009900;">&#40;</span><span style="color: #000088;">$item</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;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cSerialize</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cName</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;_S&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_COOKIE</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					<span style="color: #666666; font-style: italic;">// handle the cookie as a serialzied variable</span>
					<span style="color: #000088;">$sCookie</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/unserialize"><span style="color: #990000;">unserialize</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_COOKIE</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sCookie</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$item</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
						<span style="color: #b1b100;">return</span> <span style="color: #000088;">$sCookie</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$item</span><span style="color: #009900;">&#93;</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: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>
				<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
					<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cName</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;_&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$item</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_COOKIE</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					<span style="color: #666666; font-style: italic;">// handle the item as separate cookies</span>
					<span style="color: #b1b100;">return</span> <span style="color: #000088;">$_COOKIE</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#93;</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: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>	
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">function</span> KillCookie<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cName</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$tStamp</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/time"><span style="color: #990000;">time</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">432000</span><span style="color: #339933;">;</span>
			<a href="http://www.php.net/setcookie"><span style="color: #990000;">setcookie</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cName</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$tStamp</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cPath</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">function</span> WriteCookie<span style="color: #009900;">&#40;</span><span style="color: #000088;">$itemArr</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;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cSerialize</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>					
				<span style="color: #000088;">$sItems</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/serialize"><span style="color: #990000;">serialize</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$itemArr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cName</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;_S&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$_COOKIE</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$sItems</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$tStamp</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/time"><span style="color: #990000;">time</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cTime</span><span style="color: #339933;">;</span>
				<a href="http://www.php.net/setcookie"><span style="color: #990000;">setcookie</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span><span style="color: #000088;">$sItems</span><span style="color: #339933;">,</span><span style="color: #000088;">$tStamp</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cPath</span><span style="color: #009900;">&#41;</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;">$tStamp</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/time"><span style="color: #990000;">time</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cTime</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$itemArr</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$nam</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cName</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;_&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$nam</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$_COOKIE</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$val</span><span style="color: #339933;">;</span>
					<a href="http://www.php.net/setcookie"><span style="color: #990000;">setcookie</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span><span style="color: #000088;">$val</span><span style="color: #339933;">,</span><span style="color: #000088;">$tStamp</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cPath</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>e
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.easemarry.com/blog/php-cookie-handler-class/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PHP generate new an resizing image</title>
		<link>http://www.easemarry.com/blog/php-generate-new-an-resizing-image/</link>
		<comments>http://www.easemarry.com/blog/php-generate-new-an-resizing-image/#comments</comments>
		<pubDate>Tue, 11 Mar 2008 14:18:55 +0000</pubDate>
		<dc:creator>rueben</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Code]]></category>
		<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[php resizing]]></category>
		<category><![CDATA[php Thumbnails]]></category>
		<category><![CDATA[resizing image]]></category>
		<category><![CDATA[Thumbnails]]></category>

		<guid isPermaLink="false">http://www.easemarry.com/blog/php-generate-new-an-resizing-image/</guid>
		<description><![CDATA[

?View Code PHP1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
&#60; ?PHP     
class HanroadClass
&#123;
	/************************
	generate new an Resizing image by the PHP GD library
	Support picture format: jpg, gif, png
	$source_img:     Source image path
	$target_dir:     Target image path
	$target_name:    Target image name
	$new_width:      Target image width
	$new_height:    [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsense#co-2--></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p30code10'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p3010"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
</pre></td><td class="code" id="p30code10"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?PHP     
<span style="color: #000000; font-weight: bold;">class</span> HanroadClass
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">/************************
	generate new an Resizing image by the PHP GD library
	Support picture format: jpg, gif, png
	$source_img:     Source image path
	$target_dir:     Target image path
	$target_name:    Target image name
	$new_width:      Target image width
	$new_height:     Target image height
	$if_cut:         cutting image ?
	1(yes):          Specified high or width generated Images
	0(no):           Proportion generated Images
	**********************/</span>
	<span style="color: #000000; font-weight: bold;">function</span>  HrResize<span style="color: #009900;">&#40;</span><span style="color: #000088;">$source_img</span><span style="color: #339933;">,</span><span style="color: #000088;">$target_dir</span><span style="color: #339933;">,</span><span style="color: #000088;">$target_name</span><span style="color: #339933;">,</span><span style="color: #000088;">$new_width</span><span style="color: #339933;">,</span><span style="color: #000088;">$new_height</span><span style="color: #339933;">,</span><span style="color: #000088;">$if_cut</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//Get image format</span>
		<span style="color: #000088;">$img_type</span>   <span style="color: #339933;">=</span>   <a href="http://www.php.net/strtolower"><span style="color: #990000;">strtolower</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/strrchr"><span style="color: #990000;">strrchr</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$source_img</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//Target image path</span>
		<span style="color: #000088;">$tar_url</span>   <span style="color: #339933;">=</span>   <span style="color: #000088;">$target_dir</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$target_name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$img_type</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$img_type</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;jpg&quot;</span><span style="color: #009900;">&#41;</span>   <span style="color: #000088;">$temp_img</span>   <span style="color: #339933;">=</span>   <a href="http://www.php.net/imagecreatefromjpeg"><span style="color: #990000;">imagecreatefromjpeg</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$source_img</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: #000088;">$img_type</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;gif&quot;</span><span style="color: #009900;">&#41;</span>   <span style="color: #000088;">$temp_img</span>   <span style="color: #339933;">=</span>   <a href="http://www.php.net/imagecreatefromgif"><span style="color: #990000;">imagecreatefromgif</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$source_img</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: #000088;">$img_type</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;png&quot;</span><span style="color: #009900;">&#41;</span>   <span style="color: #000088;">$temp_img</span>   <span style="color: #339933;">=</span>   <a href="http://www.php.net/imagecreatefrompng"><span style="color: #990000;">imagecreatefrompng</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$source_img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//Source image's width and height</span>
		<span style="color: #000088;">$old_width</span>     <span style="color: #339933;">=</span>   <a href="http://www.php.net/imagesx"><span style="color: #990000;">imagesx</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$temp_img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$old_height</span>   <span style="color: #339933;">=</span>   <a href="http://www.php.net/imagesy"><span style="color: #990000;">imagesy</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$temp_img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//Change the ratio of the image before and after</span>
		<span style="color: #000088;">$new_ratio</span>   <span style="color: #339933;">=</span>   <span style="color: #000088;">$new_width</span><span style="color: #339933;">/</span><span style="color: #000088;">$new_height</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$old_ratio</span>   <span style="color: #339933;">=</span>   <span style="color: #000088;">$old_width</span><span style="color: #339933;">/</span><span style="color: #000088;">$old_height</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//Generate new image</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$if_cut</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;1&quot;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$new_width</span>     <span style="color: #339933;">=</span>   <span style="color: #000088;">$new_width</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$new_height</span>   <span style="color: #339933;">=</span>   <span style="color: #000088;">$new_height</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$old_ratio</span><span style="color: #339933;">&gt;=</span><span style="color: #000088;">$new_ratio</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$old_width</span>     <span style="color: #339933;">=</span>   <span style="color: #000088;">$old_height</span><span style="color: #339933;">*</span><span style="color: #000088;">$new_ratio</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$old_height</span>   <span style="color: #339933;">=</span>   <span style="color: #000088;">$old_height</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;">$old_width</span>     <span style="color: #339933;">=</span>   <span style="color: #000088;">$old_width</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$old_height</span>   <span style="color: #339933;">=</span>   <span style="color: #000088;">$old_width</span><span style="color: #339933;">/</span><span style="color: #000088;">$new_ratio</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">else</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$old_width</span>     <span style="color: #339933;">=</span>   <span style="color: #000088;">$old_width</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$old_height</span>   <span style="color: #339933;">=</span>   <span style="color: #000088;">$old_height</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$old_ratio</span><span style="color: #339933;">&gt;=</span><span style="color: #000088;">$new_ratio</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$new_width</span>     <span style="color: #339933;">=</span>   <span style="color: #000088;">$new_width</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$new_height</span>   <span style="color: #339933;">=</span>   <span style="color: #000088;">$new_width</span><span style="color: #339933;">/</span><span style="color: #000088;">$old_ratio</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;">$new_width</span>     <span style="color: #339933;">=</span>   <span style="color: #000088;">$new_height</span><span style="color: #339933;">*</span><span style="color: #000088;">$old_ratio</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$new_height</span>   <span style="color: #339933;">=</span>   <span style="color: #000088;">$new_height</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$new_img</span>   <span style="color: #339933;">=</span>   <a href="http://www.php.net/imagecreatetruecolor"><span style="color: #990000;">imagecreatetruecolor</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$new_width</span><span style="color: #339933;">,</span><span style="color: #000088;">$new_height</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<a href="http://www.php.net/imagecopyresampled"><span style="color: #990000;">imagecopyresampled</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$new_img</span><span style="color: #339933;">,</span><span style="color: #000088;">$temp_img</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$new_width</span><span style="color: #339933;">,</span><span style="color: #000088;">$new_height</span><span style="color: #339933;">,</span><span style="color: #000088;">$old_width</span><span style="color: #339933;">,</span><span style="color: #000088;">$old_height</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;">$img_type</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;jpg&quot;</span><span style="color: #009900;">&#41;</span>   <a href="http://www.php.net/imagejpeg"><span style="color: #990000;">imagejpeg</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$new_img</span><span style="color: #339933;">,</span><span style="color: #000088;">$tar_url</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">90</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: #000088;">$img_type</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;gif&quot;</span><span style="color: #009900;">&#41;</span>   <a href="http://www.php.net/imagegif"><span style="color: #990000;">imagegif</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$new_img</span><span style="color: #339933;">,</span><span style="color: #000088;">$tar_url</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: #000088;">$img_type</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;png&quot;</span><span style="color: #009900;">&#41;</span>   <a href="http://www.php.net/imagepng"><span style="color: #990000;">imagepng</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$new_img</span><span style="color: #339933;">,</span><span style="color: #000088;">$tar_url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$target_name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$img_type</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span> ?php
<span style="color: #000088;">$nesimg</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> HanroadClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$img1</span><span style="color: #339933;">=</span><span style="color: #000088;">$nesimg</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">HrResize</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;c:<span style="color: #000099; font-weight: bold;">\t</span>est.jpg&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;c:<span style="color: #000099; font-weight: bold;">\t</span>est_1.jpg&quot;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">120</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">120</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$img2</span><span style="color: #339933;">=</span><span style="color: #000088;">$nesimg</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">HrResize</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;c:<span style="color: #000099; font-weight: bold;">\t</span>est.jpg&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;c:<span style="color: #000099; font-weight: bold;">\t</span>est_2.jpg&quot;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">120</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">120</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000088;">$img1</span><span style="color: #339933;">:</span>
<span style="color: #339933;">&lt;</span>img src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php echo <span style="color: #006699; font-weight: bold;">$img1</span>;?/&gt;&quot;</span><span style="color: #339933;">/&gt;&lt;</span>br <span style="color: #339933;">/&gt;&lt;</span>br <span style="color: #339933;">/&gt;</span>
<span style="color: #000088;">$img2</span><span style="color: #339933;">:</span>
<span style="color: #339933;">&lt;</span>img src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php echo <span style="color: #006699; font-weight: bold;">$img2</span>;?/&gt;&quot;</span><span style="color: #339933;">/&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.easemarry.com/blog/php-generate-new-an-resizing-image/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom Form Helpers in Solar</title>
		<link>http://www.easemarry.com/blog/custom-form-helpers-in-solar/</link>
		<comments>http://www.easemarry.com/blog/custom-form-helpers-in-solar/#comments</comments>
		<pubDate>Sun, 09 Mar 2008 09:39:04 +0000</pubDate>
		<dc:creator>rueben</dc:creator>
				<category><![CDATA[Framework]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[Calendar Helper]]></category>
		<category><![CDATA[Creation]]></category>
		<category><![CDATA[Familiar Territory]]></category>
		<category><![CDATA[Form Javascript]]></category>
		<category><![CDATA[Helper Class]]></category>
		<category><![CDATA[Javascript Popup]]></category>
		<category><![CDATA[Mysite]]></category>
		<category><![CDATA[php framework]]></category>
		<category><![CDATA[Solar]]></category>
		<category><![CDATA[Solar framework]]></category>

		<guid isPermaLink="false">http://www.easemarry.com/blog/custom-form-helpers-in-solar/</guid>
		<description><![CDATA[
Another thing that Solar makes easy is the creation of custom form helpers. These can be anything outside of the usual input types (like text, checkbox, textarea, etc) and can be used to make helpful, more complex inputs for your app.
In a previous post, I worked some with the Solar_Form class to create a login [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsense#co-2--><br />
Another thing that <a href="http://www.solarphp.com/"><font color="#999999">Solar</font></a> makes easy is the creation of custom form helpers. These can be anything outside of the usual input types (like text, checkbox, textarea, etc) and can be used to make helpful, more complex inputs for your app.</p>
<p>In a <a href="http://blog.phpdeveloper.org/?p=65"><strong><font color="#325c76">previous post</font></strong></a>, I worked some with the <a href="http://solarphp.com/package/Solar_Form"><strong><font color="#325c76">Solar_Form class</font></strong></a> to create a login form. This just used simple input fields (text and password) to create the login form. I came to another part of my application where I needed a calendar helper to fill in some fields. I wanted to eliminate some of the user issues that could come with invalid dates being entered, so I opted to create a custom form field instead. The field is a normal text field, marked as READONLY with a link that launches a Javascript popup with the calendar picker.</p>
<p><span id="more-21"></span></p>
<p>First, we need a little structure &#8211; here&#8217;s how the application is structured (basically):</p>
<pre>MyApp</pre>
<pre>  App</pre>
<pre>   Base</pre>
<pre>    Helper</pre>
<pre>     FormDate.php</pre>
<pre>    Layout</pre>
<pre>    Locale</pre>
<pre>    View</pre>
<pre>   Event</pre>
<pre>   Event.php</pre>
<pre>    Helper</pre>
<pre>    Layout</pre>
<pre>    Locale</pre>
<pre>    View</pre>
<pre>     index.php</pre>
<p>There&#8217;s a few things involved here:</p>
<ul>
<li>The form helper class &#8211; <a target="_blank" href="http://www.easemarry.com/blog">FormDate.php</a></li>
<li>The <a href="http://www.easemarry.com/blog">Event.php</a> class (controller) where the form will be created</li>
<li>The View for the Event controller to output the form and some Javascript</li>
</ul>
<p>We&#8217;ll start with building the form since that&#8217;s more familiar territory:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p21code14'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2114"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code" id="p21code14"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> MySite_App_Event <span style="color: #000000; font-weight: bold;">extends</span> MySite_App_Base <span style="color: #009900;">&#123;</span>
    protected   <span style="color: #000088;">$_action_default</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'index'</span><span style="color: #339933;">;</span>
    protected   <span style="color: #000088;">$_layout</span>   <span style="color: #339933;">=</span> <span style="color: #0000ff;">'default'</span><span style="color: #339933;">;</span>
    protected   <span style="color: #000088;">$_view</span>  <span style="color: #339933;">=</span><span style="color: #0000ff;">'index'</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span>    <span style="color: #000088;">$forms</span><span style="color: #339933;">;</span> 
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> actionIndex<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$form</span> <span style="color: #339933;">=</span> Solar<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Solar_Form'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setElements</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'event_title'</span><span style="color: #339933;">=&gt;</span>array<span style="color: #009900;">&#40;</span>
                <span style="color: #0000ff;">'type'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'text'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Event Title'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'require'</span><span style="color: #339933;">=&gt;</span>true<span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'valid'</span><span style="color: #339933;">=&gt;</span>array<span style="color: #009900;">&#40;</span>
                    <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'notBlank'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Please enter an event title!'</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'event_start'</span><span style="color: #339933;">=&gt;</span>array<span style="color: #009900;">&#40;</span>
                <span style="color: #0000ff;">'type'</span>   <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'date'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'label'</span>  <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Start Date'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'require'</span><span style="color: #339933;">=&gt;</span>true<span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'valid'</span>  <span style="color: #339933;">=&gt;</span>array<span style="color: #009900;">&#40;</span>
                    <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'notBlank'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Please select a start date!'</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'sub'</span><span style="color: #339933;">=&gt;</span>array<span style="color: #009900;">&#40;</span>
                <span style="color: #0000ff;">'type'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'submit'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'create event'</span>
            <span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">feedback</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">forms</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'create_form'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$form</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>If you look close, you&#8217;ll spot something custom in there &#8211; on the event_start element, there&#8217;s a type of &#8220;date&#8221;. This how our special form helper is called. Solar does a little magic here &#8211; it looks at the types of each of the elements and looks in a few places for something that matches that type. Most of the elements are Solar&#8217;s default types so it falls back to the ones in the Solar directories. The &#8220;date&#8221; type, however, isn&#8217;t one of them and the app will break if you leave it like this.</p>
<p>So, what&#8217;s a developer to do? Well, create a custom form handler of course! This is where the FormDate.php file comes into play. Here&#8217;s what ours contains:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p21code15'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2115"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p21code15"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> MySite_App_Base_Helper_FormDate <span style="color: #000000; font-weight: bold;">extends</span> Solar_View_Helper_FormElement <span style="color: #009900;">&#123;</span> 
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> formDate<span style="color: #009900;">&#40;</span><span style="color: #000088;">$info</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_prepare<span style="color: #009900;">&#40;</span><span style="color: #000088;">$info</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'&lt;input type=&quot;text&quot;'</span>
             <span style="color: #339933;">.</span> <span style="color: #0000ff;">' name=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-/&gt;</span>_view<span style="color: #339933;">-&gt;</span><span style="color: #004000;">escape</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_name<span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;'</span>
             <span style="color: #339933;">.</span> <span style="color: #0000ff;">' value=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_view<span style="color: #339933;">-&gt;</span><span style="color: #004000;">escape</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_value<span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;'</span>
             <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_view<span style="color: #339933;">-&gt;</span><span style="color: #004000;">attribs</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_attribs<span style="color: #009900;">&#41;</span>
             <span style="color: #339933;">.</span> <span style="color: #0000ff;">' READONLY/&gt; &lt;a href=&quot;#&quot; onClick=&quot;date_picker('</span><span style="color: #0000ff;">'.$this-&gt;_view-&gt;escape($this-&gt;_name).'</span><span style="color: #0000ff;">')&quot;&gt;select&lt;/a&gt;'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>If you&#8217;ve been checking out the default Solar form fields, this should look familiar &#8211; it&#8217;s a ripoff of the default text field form helper that Solar comes with. The only addition is the Javascript-powered link there at the end that calls the date_picker application.</p>
<p>There&#8217;s a few things that need to be in place to get this to work. First off, the <strong><a href="http://www.easemarry.com/blog">class name</a></strong> needs to be the right &#8220;path&#8221; to the file. So, for our class it corresponds to MySite/App/Base/Helper to tell Solar where the file exists. If this isn&#8217;t right, Solar won&#8217;t be able to find and use the file. Next thing to look out for is the last part of the class name &#8211; FormDate for us. The second part of this is what Solar uses when the class is called. So, for example, we use FormDate because we want the type to be &#8220;date&#8221;. If we wanted one that was some kind of special field that works with Google&#8217;s Maps, we could use FormGoogle and define our custom form field inside it. Speaking of inside, the <strong><a href="http://www.easemarry.com/blog">method&#8217;s name</a></strong> has to match the class name &#8211; FormDate and formDate &#8211; and takes in the information passed to it (including the field name, the value to fill it with and attributes it might have).</p>
<p>Because this file exists in the Base controller&#8217;s Helper directory and our Event class extends the Base, we can use it. Plus, by putting it up in the Base Helper directory, we can use it in other places in the site that extend Base.</p>
<p>Now we&#8217;ll move on to the last part of the equation &#8211; the View for the Event controller:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p21code16'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2116"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p21code16"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #000000; font-weight: bold;">function</span> date_picker<span style="color: #009900;">&#40;</span>fname<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    elem<span style="color: #339933;">=</span>document<span style="color: #339933;">.</span>getElementById<span style="color: #009900;">&#40;</span>fname<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    elem<span style="color: #339933;">.</span>value<span style="color: #339933;">=</span><span style="color: #0000ff;">'08/14/1977'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span> 
<span style="color: #339933;">&lt;</span> ?php
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">forms</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'create_form'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>In the View above (our index.php file), we define the Javascript function our custom helper will use &#8211; date_picker &#8211; that takes in the element name. In a real application, this would be the place to interface with another page (or maybe even some sort of Ajax request) to let the user pick the date. As it stands, though, we&#8217;re just putting our predefined date in the field. The PHP part is simple, just an execution of the form. </p>
<p>Ideally, you&#8217;d put any and all Javascript in a few files out in the public directory of your application rather than in the view itself, but since we&#8217;re going for simplicity here I&#8217;ve just put it in the page itself. </p>
<p>So, there we go &#8211; a simple method to make a custom form handler that you can use anywhere in your application. It&#8217;s pretty easy to see how you can expand upon this to make just about any kind of custom form element that you might want&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.easemarry.com/blog/custom-form-helpers-in-solar/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Being Binary in SOAP</title>
		<link>http://www.easemarry.com/blog/being-binary-in-soap/</link>
		<comments>http://www.easemarry.com/blog/being-binary-in-soap/#comments</comments>
		<pubDate>Sat, 08 Mar 2008 11:20:53 +0000</pubDate>
		<dc:creator>rueben</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Code]]></category>
		<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[Base64 Decode]]></category>
		<category><![CDATA[Base64 Encode]]></category>
		<category><![CDATA[Base64 Encoding]]></category>
		<category><![CDATA[Binary Data]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[Data Path]]></category>
		<category><![CDATA[Input File]]></category>
		<category><![CDATA[Input Server]]></category>
		<category><![CDATA[Php Extension]]></category>
		<category><![CDATA[Php Ini]]></category>
		<category><![CDATA[Php Soap]]></category>
		<category><![CDATA[Remote Server]]></category>
		<category><![CDATA[Server Code]]></category>
		<category><![CDATA[Soap Wsdl]]></category>
		<category><![CDATA[Soapclient]]></category>

		<guid isPermaLink="false">http://www.easemarry.com/blog/being-binary-in-soap/</guid>
		<description><![CDATA[
Well, it might not be the best way to do it, but here&#8217;s a way I found to send binary data via PHP&#8217;s SOAP extension from one place to another:
Server:

?View Code PHP1
2
3
4
5
6
7
8
9
10
11
function recieveFile&#40;$data&#41;&#123;
$data=base64_decode&#40;$data&#41;;
$path='/my/file/path/img_out.gif';
$fp=fopen&#40;$path,'w+'&#41;;
if&#40;$fp&#41;&#123; fwrite&#40;$fp,$data&#41;; fclose&#40;$fp&#41;; &#125;
return strlen&#40;$data&#41;.'written';
&#125;
$input = file_get_contents&#40;”php://input”);
$server = new SoapServer&#40;'http://[my url here]/binary.wsdl',array&#40;'encoding'=&#62;'ISO-8859-1'&#41;&#41;;
$server-&#62;addFunction&#40;'recieveFile'&#41;;
$server-&#62;handle&#40;&#41;;

and the Client:

?View Code PHP1
2
3
4
5
6
7
8
9
10
11
ini_set&#40;&#34;soap.wsdl_cache_enabled&#34;, &#34;0&#34;&#41;;
//send binary data
$client=new SoapClient&#40;'http://[my url here]/binary.wsdl',array&#40;'encoding'=&#62;'ISO-8859-1'&#41;&#41;;
$data=file_get_contents&#40;'/my/file/path/img_to_send.gif'&#41;;
$ret=$client-&#62;recieveFile&#40;base64_encode&#40;$data&#41;&#41;;
print_r&#40;$ret&#41;;
&#91;/code&#93;
&#160;
It's pretty [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsense#co-2--><br />
Well, it might not be the best way to do it, but here&#8217;s a way I found to send binary data via PHP&#8217;s SOAP extension from one place to another:</p>
<p><strong><a target="_blank" href="http://www.easemarry.com/blog">Server:</a></strong></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p20code19'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2019"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p20code19"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> recieveFile<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$data</span><span style="color: #339933;">=</span><a href="http://www.php.net/base64_decode"><span style="color: #990000;">base64_decode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$path</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'/my/file/path/img_out.gif'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$fp</span><span style="color: #339933;">=</span><a href="http://www.php.net/fopen"><span style="color: #990000;">fopen</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'w+'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <a href="http://www.php.net/fwrite"><span style="color: #990000;">fwrite</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <a href="http://www.php.net/fclose"><span style="color: #990000;">fclose</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">return</span> <a href="http://www.php.net/strlen"><span style="color: #990000;">strlen</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'written'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$input</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/file_get_contents"><span style="color: #990000;">file_get_contents</span></a><span style="color: #009900;">&#40;</span>”php<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//input”);</span>
<span style="color: #000088;">$server</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SoapServer<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://[my url here]/binary.wsdl'</span><span style="color: #339933;">,</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'encoding'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'ISO-8859-1'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$server</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addFunction</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'recieveFile'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$server</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">handle</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><a target="_blank" href="http://www.easemarry.com/blog">and the <strong>Client:</strong></a></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p20code20'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2020"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p20code20"><pre class="php" style="font-family:monospace;"><a href="http://www.php.net/ini_set"><span style="color: #990000;">ini_set</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;soap.wsdl_cache_enabled&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;0&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//send binary data</span>
<span style="color: #000088;">$client</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> SoapClient<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://[my url here]/binary.wsdl'</span><span style="color: #339933;">,</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'encoding'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'ISO-8859-1'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$data</span><span style="color: #339933;">=</span><a href="http://www.php.net/file_get_contents"><span style="color: #990000;">file_get_contents</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/my/file/path/img_to_send.gif'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ret</span><span style="color: #339933;">=</span><span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">recieveFile</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/base64_encode"><span style="color: #990000;">base64_encode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a href="http://www.php.net/print_r"><span style="color: #990000;">print_r</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ret</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#91;</span><span style="color: #339933;">/</span>code<span style="color: #009900;">&#93;</span>
&nbsp;
It<span style="color: #0000ff;">'s pretty basic - the client just reads in the file'</span>s information<span style="color: #339933;">,</span> runs it through a call to <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://php.net/base64_encode&quot;</span><span style="color: #339933;">&gt;</span>base64_encode<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span> before it<span style="color: #0000ff;">'s sent off to the server. Once it'</span>s there a mirror call to <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://php.net/base64_decode&quot;</span><span style="color: #339933;">&gt;</span>base64_decode<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span> gets the content back to normal and it<span style="color: #0000ff;">'s written out to the &quot;img_out.gif&quot; file on the remote server.
&nbsp;
It'</span>s probably not the best way to <span style="color: #b1b100;">do</span> it<span style="color: #339933;">,</span> but its one that I<span style="color: #0000ff;">'ve found that works quickly and easily. I tried to just send the binary data without base64 encoding it and it didn'</span>t want to cooperate <span style="color: #009900;">&#40;</span>it was only getting the first chunk of data<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span> I don<span style="color: #0000ff;">'t know how well it'</span>ll perform with larger files<span style="color: #339933;">,</span> though <span style="color: #339933;">-</span> we shall see<span style="color: #339933;">.</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.easemarry.com/blog/being-binary-in-soap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debugging PHP code using debug_backtrace</title>
		<link>http://www.easemarry.com/blog/debugging-php-code-using-debug_backtrace/</link>
		<comments>http://www.easemarry.com/blog/debugging-php-code-using-debug_backtrace/#comments</comments>
		<pubDate>Fri, 07 Mar 2008 09:38:18 +0000</pubDate>
		<dc:creator>rueben</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Code]]></category>
		<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[Bugs]]></category>
		<category><![CDATA[Debugger]]></category>
		<category><![CDATA[Execution]]></category>
		<category><![CDATA[Php Developers]]></category>
		<category><![CDATA[Php Interpreter]]></category>
		<category><![CDATA[Trial And Error]]></category>
		<category><![CDATA[Unit Tests]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[Zendstudio]]></category>

		<guid isPermaLink="false">http://www.easemarry.com/blog/debugging-php-code-using-debug_backtrace/</guid>
		<description><![CDATA[
Most of the PHP developers debug php code in their local machine just by trial and error using &#8220;print_r&#8221;,&#8221;var_dump” and &#8220;echo&#8221;. They dont write unit tests or follow any advanced debugger like xdebug. But the problem of using these methods is you cannot fool proof your code and their might be some bugs still present [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsense#co-2--><br />
Most of the <a target="_blank" href="http://www.easemarry.com">PHP developers </a>debug php code in their local machine just by trial and error using &#8220;print_r&#8221;,&#8221;var_dump” and &#8220;echo&#8221;. They dont write unit tests or follow any advanced debugger like xdebug. But the problem of using these methods is you cannot fool proof your code and their might be some bugs still present in your code. Lets see how can we debug our code more effectively getting more information from the php interpreter itself. There is a nice function called debug_backtrace() is available in PHP to trace the root of an error. As the name implies, you can trace the execution of you code which produces the error. Have a look at the following code.</p>
<p><span id="more-13"></span></p>
<p><code><br />
&lt;?php<br />
function processUserInput($a, $b)<br />
{<br />
echo divide($a,$b);<br />
}<br />
function divide($c, $d)<br />
{<br />
print_r(debug_backtrace());<br />
}<br />
echo processUserInput(4,0);<br />
?&gt;<br />
</code><code><font size="4">This will output the following one</font></code><code></p>
<pre>Array (</pre>
<pre>[0] =&gt; Array     (</pre>
<pre>             [file] =&gt; PHPDocument1</pre>
<pre>             [line] =&gt; 5</pre>
<pre>             [function] =&gt; divide</pre>
<pre>             [args] =&gt; Array</pre>
<pre>                 (</pre>
<pre>                     [0] =&gt; 4</pre>
<pre>                     [1] =&gt; 0</pre>
<pre>                 )</pre>
<pre>          )</pre>
<pre>[1] =&gt; Array         (</pre>
<pre>             [file] =&gt; PHPDocument1</pre>
<pre>             [line] =&gt; 14</pre>
<pre>             [function] =&gt; processUserInput</pre>
<pre>             [args] =&gt; Array                 (</pre>
<pre>                     [0] =&gt; 4</pre>
<pre>                     [1] =&gt; 0</pre>
<pre>                 )</pre>
<pre>          )</pre>
<pre>[2] =&gt; Array         (</pre>
<pre>             [file] =&gt; /home/hasin/Zend/ZendStudio-5.5.0/bin/php5/dummy.php</pre>
<pre>             [line] =&gt; 1</pre>
<pre>             [args] =&gt; Array                 (</pre>
<pre>                     [0] =&gt; PHPDocument1</pre>
<pre>                 )</pre>
<pre>              [function] =&gt; include</pre>
<pre>         )</pre>
<pre>  )</pre>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.easemarry.com/blog/debugging-php-code-using-debug_backtrace/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>5 Ways to be a Better PHP Developer</title>
		<link>http://www.easemarry.com/blog/5-ways-to-be-a-better-php-developer/</link>
		<comments>http://www.easemarry.com/blog/5-ways-to-be-a-better-php-developer/#comments</comments>
		<pubDate>Fri, 07 Mar 2008 09:26:42 +0000</pubDate>
		<dc:creator>rueben</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[Array Functions]]></category>
		<category><![CDATA[Code Documentation]]></category>
		<category><![CDATA[Core Functions]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Documentation Styles]]></category>
		<category><![CDATA[Freenode]]></category>
		<category><![CDATA[Hot]]></category>
		<category><![CDATA[Learn Php]]></category>
		<category><![CDATA[Newbie]]></category>
		<category><![CDATA[Open Source Code]]></category>
		<category><![CDATA[Personal Tutors]]></category>
		<category><![CDATA[Php Developer]]></category>
		<category><![CDATA[Php Manual]]></category>
		<category><![CDATA[Productivity]]></category>
		<category><![CDATA[Source Php]]></category>
		<category><![CDATA[Web Applications]]></category>
		<category><![CDATA[Wheel]]></category>

		<guid isPermaLink="false">http://www.easemarry.com/blog/5-ways-to-be-a-better-php-developer/</guid>
		<description><![CDATA[
Often, an inexperienced PHP developer will hop onto IRC and ask a question in ##php on Freenode. And if the question is trivial, the answer seems obvious or they simply seem like a newbie, they may soon find themselves bombarded with such comments as “RTFM”, “Go learn PHP”, “We are not your personal tutors” or [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsense#co-2--><br />
Often, an inexperienced PHP developer will hop onto IRC and ask a question in ##php on Freenode. And if the question is trivial, the answer seems obvious or they simply seem like a newbie, they may soon find themselves bombarded with such comments as “RTFM”, “Go learn PHP”, “We are not your personal tutors” or simply “You need to become a better PHP developer”. So, how is it that one becomes a better PHP developer? In this post, I’ll outline five ways to be a better developer, improve your productivity, write less code and achieve more with your web applications.<span id="more-36"></span>There’s always more to learn when it comes to PHP development. New core functions, new frameworks, new design patterns, new code documentation styles. Here are some of the best ways you can become a better PHP developer.</p>
<p><strong>1. Read the manual<br />
</strong>I really can’t emphasize this enough &#8211; there’s a lot to be learned just reading the PHP manual. Especially check out the string and array functions. There’s a lot of functionality available right there, and often by reading through the manual you’ll find you’ve been reinventing the wheel in past projects when you could have just used a core function. The manual is your friend.</p>
<p><strong>2. Browse through some code</strong><br />
PHP has a lot of open source code out there. So why not learn from it? Download an open source PHP application and have a read through the code. The bigger projects are probably better, as they’ll have more complex structures and systems in place but also more thorough documentation explaining it all. Check out <a target="_blank" href="http://www.easemarry.com/blog/">SourceForge.net</a> if you can’t find a good place to start.</p>
<p><strong>3. Learn a new framework</strong><br />
There are more PHP frameworks out there than you’ve had hot dinners; a lot of them are open source and available online if you know where to look. Try the major ones first &#8211; <a target="_blank" href="http://phpframeworks.com/">phpframeworks.com</a> has a good list. Your framework can never be entirely complete, your next job may require a different framework and you might just find the functionality of another comes in handy in one of your projects.</p>
<p><strong>4. Research</strong><br />
You’ve probably heard a lot of terminology and discussed in the context of PHP web development. From OOP to MVC, KISS to DRY, YAML to INI, even REST to XML-RPC, there are hundreds of technical concepts out there that could directly relate to your work. You may have formed a basic understanding of them, but do you really know what they are or what they mean for you? Spend some time doing real research; Wikipedia is a good place to start. You’re bound to learn something new.</p>
<p><strong>5. Learn OOP</strong><br />
Maybe this follows on a little from the previous point, but OOP is more important than you think. Do you really know about PHP5’s implementation OOP? For example, are you familiar with abstract classes, interfaces, the implements keyword, static methods and properties, the ‘protected’ access modifier? Even many experienced PHP developers fall down in this area. If you make use of the features of OOP, you could save yourself a lot of development time.</p>
<p>So there you have it. Five, straightforward yet significant ways to be a better PHP developer.</p>
<p><a href="http://www.developertutorials.com/blog/web/5-ways-to-be-a-better-php-developer-36/">http://www.developertutorials.com/blog/web/5-ways-to-be-a-better-php-developer-36/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.easemarry.com/blog/5-ways-to-be-a-better-php-developer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Uses KSES to filter the data-in safely</title>
		<link>http://www.easemarry.com/blog/uses-kses-to-filter-the-data-in-safely/</link>
		<comments>http://www.easemarry.com/blog/uses-kses-to-filter-the-data-in-safely/#comments</comments>
		<pubDate>Thu, 06 Mar 2008 17:53:29 +0000</pubDate>
		<dc:creator>rueben</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Code]]></category>
		<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[Acronym]]></category>
		<category><![CDATA[Array Name]]></category>
		<category><![CDATA[Attribute]]></category>
		<category><![CDATA[Crack]]></category>
		<category><![CDATA[Development Personnel]]></category>
		<category><![CDATA[First Principle]]></category>
		<category><![CDATA[Gregarius]]></category>
		<category><![CDATA[Headache]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Source Tool]]></category>
		<category><![CDATA[Wp]]></category>

		<guid isPermaLink="false">http://www.easemarry.com/blog/uses-kses-to-filter-the-data-in-safely/</guid>
		<description><![CDATA[
The safe first principle is never needs to believe any exterior data in PHP! How effective achieves this is one of each development personnel&#8217;s difficult. Before has not used webeditor, this basically quite good processing.
But if has used webeditor, how to guarantee that the user the data, simultaneously achieves safely (for example prevents the XSS [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsense#co-2--><br />
The safe first principle is never needs to believe any exterior data in PHP! How effective achieves this is one of each development personnel&#8217;s difficult. Before has not used webeditor, this basically quite good processing.</p>
<p>But if has used webeditor, how to guarantee that the user the data, simultaneously achieves safely (for example prevents the XSS crack), indeed is the headache question.<dnt></dnt></p>
<p>Here I recommend one to open the source tool &#8211; - KSES. KESS only permits the user input the data format and the attribute.<dnt></dnt></p>
<p>For example you only allowed the input saying</p>
<p>&lt;a href=&#8221;" mce_href=&#8221;"&gt;<br />
that<br />
&lt;a href=&#8221; &#8221; title=&#8221;"&gt;<br />
will include in <dnt></dnt><dnt></dnt>that <dnt></dnt><dnt></dnt>title to filter.<dnt></dnt></p>
<p>KSES is useful in WP and Gregarius, is a very easy to use thing. The use is also very simple, but is only not good, does not have the useful kind to seal, possibly this also has author own reason.</p>
<p>Example:</p>
<p>&lt;?php<br />
$kses_allowed = array (&#8217;address&#8217; =&gt; array (),<br />
&#8216;a&#8217; =&gt; array (&#8217;href&#8217; =&gt; array (),<br />
&#8216;title&#8217; =&gt; array (),<br />
&#8216;rel&#8217; =&gt; array (),<br />
&#8216;rev&#8217; =&gt; array (),<br />
&#8216;name&#8217; =&gt; array ()),<br />
&#8216;abbr&#8217; =&gt; array (&#8217;title&#8217; =&gt; array ()),<br />
&#8216;acronym&#8217; =&gt; array (&#8217;title&#8217; =&gt; array ()),<br />
&#8216;b&#8217; =&gt; array (),<br />
&#8216;big&#8217; =&gt; array (),<br />
&#8216;blockquote&#8217; =&gt; array (&#8217;cite&#8217; =&gt; array ()),<br />
&#8216;br&#8217; =&gt; array (),<br />
&#8216;button&#8217; =&gt; array (&#8217;disabled&#8217; =&gt; array (),<br />
&#8216;name&#8217; =&gt; array (),<br />
&#8216;type&#8217; =&gt; array (),<br />
&#8216;value&#8217; =&gt; array ()),<br />
&#8216;caption&#8217; =&gt; array (&#8217;align&#8217; =&gt; array ()),<br />
&#8216;code&#8217; =&gt; array (),<br />
&#8216;col&#8217; =&gt; array (&#8217;align&#8217; =&gt; array (),<br />
&#8216;char&#8217; =&gt; array (),<br />
&#8216;charoff&#8217; =&gt; array (),<br />
&#8217;span&#8217; =&gt; array (),<br />
&#8216;valign&#8217; =&gt; array (),<br />
&#8216;width&#8217; =&gt; array ()),<br />
&#8216;del&#8217; =&gt; array (&#8217;datetime&#8217; =&gt; array ()),<br />
&#8216;dd&#8217; =&gt; array (),<br />
&#8216;div&#8217; =&gt; array (&#8217;align&#8217; =&gt; array ()),<br />
&#8216;dl&#8217; =&gt; array (),<br />
&#8216;dt&#8217; =&gt; array (),<br />
&#8216;em&#8217; =&gt; array (),<br />
&#8216;fieldset&#8217; =&gt; array (),<br />
&#8216;font&#8217; =&gt; array (&#8217;color&#8217; =&gt; array (),<br />
&#8216;face&#8217; =&gt; array (),<br />
&#8217;size&#8217; =&gt; array ()),<br />
&#8216;form&#8217; =&gt; array (&#8217;action&#8217; =&gt; array (),<br />
&#8216;accept&#8217; =&gt; array (),<br />
&#8216;accept-charset&#8217; =&gt; array (),<br />
&#8216;enctype&#8217; =&gt; array (),<br />
&#8216;method&#8217; =&gt; array (),<br />
&#8216;name&#8217; =&gt; array (),<br />
&#8216;target&#8217; =&gt; array ()),<br />
&#8216;h1&#8242; =&gt; array (&#8217;align&#8217; =&gt; array ()),<br />
&#8216;h2&#8242; =&gt; array (&#8217;align&#8217; =&gt; array ()),<br />
&#8216;h3&#8242; =&gt; array (&#8217;align&#8217; =&gt; array ()),<br />
&#8216;h4&#8242; =&gt; array (&#8217;align&#8217; =&gt; array ()),<br />
&#8216;h5&#8242; =&gt; array (&#8217;align&#8217; =&gt; array ()),<br />
&#8216;h6&#8242; =&gt; array (&#8217;align&#8217; =&gt; array ()),<br />
&#8216;hr&#8217; =&gt; array (&#8217;align&#8217; =&gt; array (),<br />
&#8216;noshade&#8217; =&gt; array (), &#8217;size&#8217; =&gt; array (),<br />
&#8216;width&#8217; =&gt; array ()),<br />
&#8216;i&#8217; =&gt; array (),<br />
&#8216;img&#8217; =&gt; array (&#8217;alt&#8217; =&gt; array (),<br />
&#8216;align&#8217; =&gt; array (),<br />
&#8216;border&#8217; =&gt; array (),<br />
&#8216;height&#8217; =&gt; array (),<br />
&#8216;hspace&#8217; =&gt; array (),<br />
&#8216;longdesc&#8217; =&gt; array (),<br />
&#8216;vspace&#8217; =&gt; array (),<br />
&#8217;src&#8217; =&gt; array (),<br />
&#8216;width&#8217; =&gt; array ()),<br />
&#8216;ins&#8217; =&gt; array (&#8217;datetime&#8217; =&gt; array (),<br />
&#8216;cite&#8217; =&gt; array ()),<br />
&#8216;kbd&#8217; =&gt; array (),<br />
&#8216;label&#8217; =&gt; array (&#8217;for&#8217; =&gt; array ()),<br />
&#8216;legend&#8217; =&gt; array (&#8217;align&#8217; =&gt; array ()),<br />
&#8216;li&#8217; =&gt; array (),<br />
&#8216;p&#8217; =&gt; array (&#8217;align&#8217; =&gt; array ()),<br />
&#8216;pre&#8217; =&gt; array (&#8217;width&#8217; =&gt; array ()),<br />
&#8216;q&#8217; =&gt; array (&#8217;cite&#8217; =&gt; array ()),<br />
&#8217;s&#8217; =&gt; array (),<br />
&#8217;strike&#8217; =&gt; array (),<br />
&#8217;strong&#8217; =&gt; array (),<br />
&#8217;sub&#8217; =&gt; array (),<br />
&#8217;sup&#8217; =&gt; array (),<br />
&#8216;table&#8217; =&gt; array (&#8217;align&#8217; =&gt; array (),<br />
&#8216;bgcolor&#8217; =&gt; array (),<br />
&#8216;border&#8217; =&gt; array (),<br />
&#8216;cellpadding&#8217; =&gt; array (),<br />
&#8216;cellspacing&#8217; =&gt; array (),<br />
&#8216;rules&#8217; =&gt; array (),<br />
&#8217;summary&#8217; =&gt; array (),<br />
&#8216;width&#8217; =&gt; array ()),<br />
&#8216;tbody&#8217; =&gt; array (&#8217;align&#8217; =&gt; array (),<br />
&#8216;char&#8217; =&gt; array (), &#8216;charoff&#8217; =&gt; array (),<br />
&#8216;valign&#8217; =&gt; array ()),<br />
&#8216;td&#8217; =&gt; array (&#8217;abbr&#8217; =&gt; array (),<br />
&#8216;align&#8217; =&gt; array (),<br />
&#8216;axis&#8217; =&gt; array (),<br />
&#8216;bgcolor&#8217; =&gt; array (),<br />
&#8216;char&#8217; =&gt; array (),<br />
&#8216;charoff&#8217; =&gt; array (),<br />
&#8216;colspan&#8217; =&gt; array (),<br />
&#8216;headers&#8217; =&gt; array (),<br />
&#8216;height&#8217; =&gt; array (),<br />
&#8216;nowrap&#8217; =&gt; array (),<br />
&#8216;rowspan&#8217; =&gt; array (),<br />
&#8217;scope&#8217; =&gt; array (),<br />
&#8216;valign&#8217; =&gt; array (),<br />
&#8216;width&#8217; =&gt; array ()),<br />
&#8216;textarea&#8217; =&gt; array (&#8217;cols&#8217; =&gt; array (),<br />
&#8216;rows&#8217; =&gt; array (), &#8216;disabled&#8217; =&gt; array (),<br />
&#8216;name&#8217; =&gt; array (),<br />
&#8216;readonly&#8217; =&gt; array ()),<br />
&#8216;tfoot&#8217; =&gt; array (&#8217;align&#8217; =&gt; array (),<br />
&#8216;char&#8217; =&gt; array (),<br />
&#8216;charoff&#8217; =&gt; array (),<br />
&#8216;valign&#8217; =&gt; array ()),<br />
&#8216;th&#8217; =&gt; array (&#8217;abbr&#8217; =&gt; array (),<br />
&#8216;align&#8217; =&gt; array (),<br />
&#8216;axis&#8217; =&gt; array (),<br />
&#8216;bgcolor&#8217; =&gt; array (),<br />
&#8216;char&#8217; =&gt; array (),<br />
&#8216;charoff&#8217; =&gt; array (),<br />
&#8216;colspan&#8217; =&gt; array (),<br />
&#8216;headers&#8217; =&gt; array (),<br />
&#8216;height&#8217; =&gt; array (),<br />
&#8216;nowrap&#8217; =&gt; array (),<br />
&#8216;rowspan&#8217; =&gt; array (),<br />
&#8217;scope&#8217; =&gt; array (),<br />
&#8216;valign&#8217; =&gt; array (),<br />
&#8216;width&#8217; =&gt; array ()),<br />
&#8216;thead&#8217; =&gt; array (&#8217;align&#8217; =&gt; array (),<br />
&#8216;char&#8217; =&gt; array (),<br />
&#8216;charoff&#8217; =&gt; array (),<br />
&#8216;valign&#8217; =&gt; array ()),<br />
&#8216;title&#8217; =&gt; array (),<br />
&#8216;tr&#8217; =&gt; array (&#8217;align&#8217; =&gt; array (),<br />
&#8216;bgcolor&#8217; =&gt; array (),<br />
&#8216;char&#8217; =&gt; array (),<br />
&#8216;charoff&#8217; =&gt; array (),<br />
&#8216;valign&#8217; =&gt; array ()),<br />
&#8216;tt&#8217; =&gt; array (),<br />
&#8216;u&#8217; =&gt; array (),<br />
&#8216;ul&#8217; =&gt; array (),<br />
&#8216;ol&#8217; =&gt; array (),<br />
&#8216;var&#8217; =&gt; array ()<br />
);<br />
$string=kses($string, $kses_allowed);<br />
?&gt;<br />
<dnt></dnt></p>
]]></content:encoded>
			<wfw:commentRss>http://www.easemarry.com/blog/uses-kses-to-filter-the-data-in-safely/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Raises the efficiency in PHP mode through the factory pattern [reprint]</title>
		<link>http://www.easemarry.com/blog/raises-the-efficiency-in-php-mode-through-the-factory-pattern-reprint/</link>
		<comments>http://www.easemarry.com/blog/raises-the-efficiency-in-php-mode-through-the-factory-pattern-reprint/#comments</comments>
		<pubDate>Thu, 06 Mar 2008 09:32:05 +0000</pubDate>
		<dc:creator>rueben</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Code]]></category>
		<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[Documents Index]]></category>
		<category><![CDATA[Efficiency]]></category>
		<category><![CDATA[Headache]]></category>
		<category><![CDATA[Php Class]]></category>
		<category><![CDATA[System Development]]></category>

		<guid isPermaLink="false">http://www.easemarry.com/blog/archives/raises-the-efficiency-in-php-mode-through-the-factory-pattern-reprint/</guid>
		<description><![CDATA[
  Conducting large-scale system development time, I always worry whether it should include every possible use of the class library document.
        If it is included in use, the development will bring great trouble. Because I am impossible to know in advance which place will use which kind. Moreover, if each page, in accordance with the [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsense#co-2--><br />
  Conducting large-scale system development time, I always worry whether it should include every possible use of the class library document.<br />
        If it is included in use, the development will bring great trouble. Because I am impossible to know in advance which place will use which kind. Moreover, if each page, in accordance with the need to include or require, which is a headache, we because of will often forget that include will cause warning or fatal.</p>
<p>       If the overall situation in a document containing all of the class library, and then all the pages contain the whole document. Thus, although simplified the work, but has actually brought the efficiency drop. Because php will contain to each document to carry on the examination. Although the PHP efficiency is very high, but examines one big pile of kind, will bring some performance the drop, specially in a large-scale system.<br />
        Has the method to be possible to satisfy both sides? Certainly there,The method is the factory pattern.<br />
        We have established the following four documents.</p>
<p dir="ltr"><a target="_blank" href="http://www.easemarry.com/">index.php</a></p>
<p><code><span style="color: #000000"></span></code><code><span style="color: #000000"></span></code><code><span style="color: #000000"></span></code><code><span style="color: #000000"></span></code><code><span style="color: #000000"></span></code><code><span style="color: #000000"></span></code><code><span style="color: #000000"></span></code><code><span style="color: #000000"></p>
<p style="overflow: auto" class="code"><span style="color: #0000bb"><font color="#000000" face="Georgia">&lt;?php<br />
include_once("f.inc.php");<br />
$f=new factory;<br />
$t1=&amp;$f-&gt;create('T1');<br />
echo $t1-&gt;getName();<br />
echo $config;<br />
?&gt;  </font></span></p>
<p></span></p>
<p style="overflow: auto" class="code"><span style="color: #0000bb"><font color="#000000" face="Georgia">f.inc.php</font></span></p>
<p><span style="color: #0000bb"></span><span style="color: #0000bb"></span><span style="color: #0000bb"></span><span style="color: #0000bb"></span><span style="color: #0000bb"></span><span style="color: #0000bb"></span><span style="color: #0000bb"></span><span style="color: #0000bb"><font color="#000000" face="Georgia"></p>
<p style="overflow: auto" class="code">&lt;?php<br />
class factory<br />
{<br />
    function factory()<br />
    {<br />
        $this-&gt;mClasses=array('T1'=&gt;'t1.inc.php','T2'=&gt;'t2.inc.php');<br />
    }<br />
    function &amp;create($class)<br />
    {<br />
        if (!class_exists($class))<br />
        {<br />
            require_once($this-&gt;mClasses[$class]);<br />
        }<br />
        return new $class;<br />
    }<br />
}<br />
?&gt;
</p>
<p style="overflow: auto" class="code">t1.inc.php</p>
<p style="overflow: auto" class="code">&lt;?php<br />
global $config;<br />
$config='surfchen';<br />
class T1<br />
{<br />
    var $mName='name::T1';<br />
    function getName()<br />
    {<br />
        return $this-&gt;mName;<br />
    }<br />
}<br />
?&gt;
</p>
<p style="overflow: auto" class="code">t2.inc.php</p>
<p style="overflow: auto" class="code">&lt;?php<br />
class T2<br />
{<br />
    function T2()<br />
    {<br />
        echo 't2 is ok';<br />
    }<br />
}<br />
?&gt; </p>
<p></font></span></code><code><span style="color: #000000"></span></code><code><span style="color: #000000"></span></code><code><span style="color: #000000"></span></code><code><span style="color: #000000"></span></code><code><span style="color: #000000"></span></code><code><span style="color: #000000"></span></code><code><span style="color: #000000"></span></code><code><span style="color: #000000"></p>
<p style="overflow: auto" class="code">&nbsp;</p>
<p></span></code></p>
<p style="overflow: auto" class="code">In index.php, we passed a factory to create other instance,</p>
<p style="overflow: auto" class="code">In the factory, the preservation of an array $this-&gt;mClasses,format for the array ( &#8220;class name&#8221; =&gt; &#8220;class file path&#8221;).</p>
<p style="overflow: auto" class="code">We through the <a target="_blank" href="http://www.easemarry.com/blog/">factory::create() </a>to create an instance, in create(), the first test of whether to exist, if don&#8217;t exist, based on $this-&gt; mClasses category corresponding to the type of document contains come. Then create and return a such examples.</p>
<p style="overflow: auto" class="code">Thus, we need only to factory-type document contains implementation of the script (example:index.php) on it.<br />
        Everybody possibly also noted in t1.inc.php in two lines of code.<br />
  Global $config;<br />
  $Config = &#8217;surfchen&#8217;;</p>
<p style="overflow: auto" class="code">        Why do we need global? Because t1.inc.php is include in factory::create, in the t1 document&#8217;s variables will approve the default function to the class. Therefore,we need one of the variables (example: $config) to index.php to global access to.<br />
        Operation index.php, will be output<br />
        Name:: T1surfchen
</p>
<p style="overflow: auto" class="code"><a href="http://www.easemarry.com/blog/">http://www.easemarry.com/blog/</a></p>
<p style="overflow: auto" class="code">&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.easemarry.com/blog/raises-the-efficiency-in-php-mode-through-the-factory-pattern-reprint/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Skill: PHP optimization, buffering, compression practical solutions</title>
		<link>http://www.easemarry.com/blog/skill-php-optimization-buffering-compression-practical-solutions/</link>
		<comments>http://www.easemarry.com/blog/skill-php-optimization-buffering-compression-practical-solutions/#comments</comments>
		<pubDate>Thu, 06 Mar 2008 02:09:15 +0000</pubDate>
		<dc:creator>rueben</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[Accomplishment]]></category>
		<category><![CDATA[Application Load]]></category>
		<category><![CDATA[Bottlenecks]]></category>
		<category><![CDATA[Code Optimization]]></category>
		<category><![CDATA[Engine Optimization]]></category>
		<category><![CDATA[Intermediate Code]]></category>
		<category><![CDATA[Optimization Help]]></category>
		<category><![CDATA[Optimization Level]]></category>
		<category><![CDATA[Platform Versions]]></category>
		<category><![CDATA[Practical Solutions]]></category>
		<category><![CDATA[Prerequisite]]></category>
		<category><![CDATA[Script Programming Language]]></category>
		<category><![CDATA[Superiority]]></category>
		<category><![CDATA[Web Programming Language]]></category>
		<category><![CDATA[Zend Cache]]></category>
		<category><![CDATA[Zend Engine]]></category>
		<category><![CDATA[Zend Optimizer]]></category>
		<category><![CDATA[Zend Technologies]]></category>

		<guid isPermaLink="false">http://www.easemarry.com/blog/archives/skill-php-optimization-buffering-compression-practical-solutions/</guid>
		<description><![CDATA[
As the popular Web programming language, the PHP biggest superiority is a speed. PHP4 already did in this aspect has been good, and you almost could not find it faster than the script programming language. However, if your application load large, and bandwidth is relatively small, or there are other bottlenecks affecting the performance of [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsense#co-2--><br />
As the popular Web programming language, the PHP biggest superiority is a speed. <a target="_blank" href="http://www.easemarry.com/blog">PHP4</a> already did in this aspect has been good, and you almost could not find it faster than the script programming language. However, if your application load large, and bandwidth is relatively small, or there are other bottlenecks affecting the performance of your server, then you may wish to try out for you the author of several prescription to see if it works.</p>
<p>First, code optimization</p>
<p>On a code optimization, perhaps you think is neat and clear code, but this is not the meaning of this, because if we seek rate, we should PHP source to be adjusted accordingly. Generally speaking is to remove redundant Notes, code unreadable. But this is a good accomplishment for programmers, it is inconceivable. Fortunately Zend Technologies announced the Zend engine optimization can help you do this. It is now free, but you must follow <a target="_blank" href="http://www.easemarry.com/blog">Zend Optimizer license.</a> This product can be the engine optimized intermediate code.</p>
<p>This engine is relatively simple to install, download corresponding platform versions later, untied compressed files, and then in the php.ini file add the following two lines inside, restart the Web server, to get.</p>
<p>Zend_optimizer.optimization_level = 15<br />
Zend_extension = &#8220;/ path / to / ZendOptimizer.so&#8221;<br />
Zend_loader.enable = Off</p>
<p>If Win32 platform, it will be:</p>
<p>Zend_optimizer.optimization_level = 15<br />
Zend_extension_ts = &#8220;C: /path / to / ZendOptimizer.dll&#8221;<br />
Zend_loader.enable = Off</p>
<p>Ah! Not mistaken? How is three lines? In fact, the third line is optional. Seem to switch off because zend_loader can improve the speed, and is therefore worthy of this third line put php.ini. It must be noted that switching off is a prerequisite for the use of Zend you do not have encryption procedures.</p>
<p>Second, the buffer</p>
<p>If you want to further enhance the speed, we need to consider adopting buffer technology. Some optional solutions, including Zend Cache (test version), APC, and Afterburner Cache, such as another jpCache.</p>
<p>These are of a buffer module, the first time right. Php documents requested the intermediate code stored in the Web server&#8217;s memory, and then later on the request to return to &#8220;build good&#8221; version. This reduction of the disk to read and write, but in the memory, so this process can significantly improve application performance,</p>
<p>Off-the-shelf products such comparison, in the end choose whom?</p>
<p>Zend Cache is a good commercial product, in the first loading of those great PHP pages, you will clearly feel the speed increase, the server will leave more resources. Unfortunately, this product is to spend money, but in some cases, you may not mean the money.</p>
<p>Afterburner Cache is Bware Technologies products, is still in Beta version, and Zend Cashe appear to be the same, but it did not achieve good results Zend Cache, we can not and Zend engine optimization work together, but it is free, so I use this module.</p>
<p>APC (Alternative PHP Cache) is issued by the Community Connect has a free module can be used in production may seem environment.</p>
<p>Third, Web content compression</p>
<p>The increasingly crowded network, saving bandwidth like water conservation, is very much worth advocated. According to IETF standards, the majority of the browser should support the use of the contents of gzip compression. In other words you can use gzip compressed content sent to the browser, the browser will be transparent to extract the data.</p>
<p>Mod_gzip is Remote Communications Company introduced free Apache module, able to static Web content compression sent to the browser. For most static pages, this module is suitable. Although</p>
<p>Remotecommunications company said that this module supports all those who mod_php, mod_perl, mod what the dynamic content, but it still does not work, mod_gzip mailing list, the problem is estimated to 1.3.14.6 f can be resolved.</p>
<p>If the dynamic content compression, we can use class.gzip_encode.php, one in the script at the beginning and end of the use of PHP. For the entire site is in the php.ini auto_prepend and auto_append in which the function call. You can read the details of the procedures, which notes very well, and the author almost anything to tell you. But before use, your PHP to build support for the zlib.</p>
<p>For PHP 4.0.4, a new solution is the use of ob_gzhandler, to achieve the above categories and the same effect, as long as simple php.ini joined in the following sentence can be:</p>
<p>Output_handler = ob_gzhandler;</p>
<p>This allows PHP output caching, and compression of all output. If there is anything special reasons do not want to have all the contents of compressed output, can be used in the. Htaccess files by adding the following line in the corresponding directory under the file compression.</p>
<p>Php_value output_handler ob_gzhandler</p>
<p>Can be directly added to the code in PHP:</p>
<p>Ob_start ( &#8220;ob_gzhandler&#8221;);</p>
<p>The compression technology is very effective, but Netscape Communicator users, because Bunaiyasu graphics files, so do not seem to complete the jpeg and gif file compression, IE do not have this problem.</p>
<p>Conclusion:</p>
<p>This paper discussed the use of technology should be able to improve the performance of your site, but it should be noted that:</p>
<p>&#8211; PHP may not lead to bottlenecks reasons, carefully examined for other reasons (for example: Database)</p>
<p>&#8211; You can not regulate the server performance to the highest state. Therefore, in the buffer prior to complain of PHP and consider whether to upgrade the server, or to use dynamic load balancing technology.</p>
<p>&#8211; Do not underestimate the content compression, in your 100 Mb of internal online PHP applications that improve the speed, do not forget to use the modem users where 100 Kb blame your HTML page.</p>
<p><a href="http://www.easemarry.com/blog">http://www.easemarry.com/blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.easemarry.com/blog/skill-php-optimization-buffering-compression-practical-solutions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

