Pure PHP - PHP unconventional http://www.pure-php.de en Lightweight, but Powerful PHP5 XML-RPC Server http://www.pure-php.de/node/31 <p>I have written a XML-Server in PHP5.<br /> It is very easy to use. Just include the file and run the server.<br /> It has some restrictions, it accepts only functions and static methods. you don't have to to change your code if your methods return a php type. (string, array, integer)<br /> Example<br /> <div class="codeblock"><code><span style="color: #000000"> <span style="color: #0000CC">&lt;?php<br />$ws&nbsp;</span><span style="color: #006600">=&nbsp;new&nbsp;</span><span style="color: #0000CC">XML_RPC_Server</span><span style="color: #006600">();<br /></span><span style="color: #0000CC">$ws</span><span style="color: #006600">-&gt;</span><span style="color: #0000CC">registerFunction</span><span style="color: #006600">(</span><span style="color: #CC0000">'getTime'</span><span style="color: #006600">);<br /></span><span style="color: #0000CC">$ws</span><span style="color: #006600">-&gt;</span><span style="color: #0000CC">registerMethod</span><span style="color: #006600">(</span><span style="color: #CC0000">'Product::getPrice'</span><span style="color: #006600">);<br /></span><span style="color: #0000CC">$ws</span><span style="color: #006600">-&gt;</span><span style="color: #0000CC">registerMethod</span><span style="color: #006600">(</span><span style="color: #CC0000">'Product::getDetail'</span><span style="color: #006600">);<br /></span><span style="color: #0000CC">$ws</span><span style="color: #006600">-&gt;</span><span style="color: #0000CC">registerMethod</span><span style="color: #006600">(</span><span style="color: #CC0000">'Product::getBinaryPicture'</span><span style="color: #006600">);<br /></span><span style="color: #0000CC">$ws</span><span style="color: #006600">-&gt;</span><span style="color: #0000CC">run</span><span style="color: #006600">();<br /></span><span style="color: #0000CC">?&gt;</span> </span> </code></div><br /> Example Source,<br /> http://www.pure-php.com/php/service.source.php<br /> The Server<br /> http://www.pure-php.com/php/xmlrpc.php.txt</p> <p><a href="http://www.pure-php.de/node/31">read more</a></p> http://www.pure-php.de/node/31#comment PHP Thu, 09 Mar 2006 22:59:47 +0100 pure-php 31 at http://www.pure-php.de PHP Style Cookie and Get Parameters in JavaScript http://www.pure-php.de/node/30 <p>For lazy phpers, with this function you can read cookies and get parameters in javascript in php style.<br /> (I use php tags to highlight the code)<br /> Example<br /> <div class="codeblock"><code><span style="color: #000000"> <span style="color: #0000CC">&lt;?php<br />populateRequest</span><span style="color: #006600">();<br />if(&nbsp;</span><span style="color: #0000CC">$_COOKIE</span><span style="color: #006600">[</span><span style="color: #CC0000">'sid'</span><span style="color: #006600">]&nbsp;)&nbsp;{<br /></span><span style="color: #FF9900">//&nbsp;do&nbsp;something<br /></span><span style="color: #006600">}<br />if(&nbsp;</span><span style="color: #0000CC">$_GET</span><span style="color: #006600">[</span><span style="color: #CC0000">'cmd'</span><span style="color: #006600">]&nbsp;==&nbsp;</span><span style="color: #CC0000">'login'&nbsp;</span><span style="color: #006600">)&nbsp;{<br /></span><span style="color: #FF9900">//&nbsp;do&nbsp;something<br /></span><span style="color: #006600">}<br /></span><span style="color: #0000CC">?&gt;</span> </span> </code></div></p> <p><a href="http://www.pure-php.de/node/30">read more</a></p> http://www.pure-php.de/node/30#comment JavaScript / Ajax Thu, 23 Feb 2006 09:56:08 +0100 pure-php 30 at http://www.pure-php.de Java Class Search with Ajax, powered by PHP http://www.pure-php.de/node/28 <p><a href="http://www.pure-java.com/">Pure-java.com</a> search for java classes with use of ajax. The site is powered by PHP5</p> http://www.pure-php.de/node/28#comment Sun, 12 Feb 2006 22:40:00 +0100 pure-php 28 at http://www.pure-php.de The easist way to avoid double clicks in submit buttons http://www.pure-php.de/node/27 <p>Most of the sites have this problem, for example, when user want to create an account. The fill in the registration from, and submit the form. If the site is too slow at that moment. they would click again, and you have double entries.</p> <p>With this JavaScript class, you deactivate this. Just put that and end of your site.<br /> <code><br /> function ClickObServer(){<br /> this.deactivateDoubleClicks = function() {<br /> this.checkClicks(document.getElementsByTagName("a"));<br /> this.checkClicks(document.getElementsByTagName("input"));<br /> }<br /> this.checkClicks = function ( el ){<br /> for (var i = 0; i &lt; el.length; i++) {</p> <p><a href="http://www.pure-php.de/node/27">read more</a></p> http://www.pure-php.de/node/27#comment JavaScript / Ajax Fri, 25 Nov 2005 21:30:00 +0100 pure-php 27 at http://www.pure-php.de Pure PHP up again http://www.pure-php.de/node/26 <p>After several months pure-php is up agian, and I would try to post in the next days</p> http://www.pure-php.de/node/26#comment Tue, 22 Nov 2005 22:51:00 +0100 pure-php 26 at http://www.pure-php.de PHP-Magazine's security leak closed http://www.pure-php.de/node/25 <p>PHP-Magazine has closed its security leak. Yesterday I received an email from PHP-Magazine. My posting form the last week is not up to date anymore. The company, which has written the Powerslave CMS has also been informed, and they would fix it. The security leak remains on many sites, with the Powerslave CMS. </p> <p>The user of Powersalve can ask me for a quick solution. The can also ask the company behind Powerslave.</p> http://www.pure-php.de/node/25#comment Security Wed, 06 Apr 2005 09:28:00 +0200 pure-php 25 at http://www.pure-php.de Security matters, specially for PHP-Magazine, some source code publicly accessible! http://www.pure-php.de/node/24 <p><strong><br /> PHP-Magazine has fixed this secutrity leak, it is not possible to read any source code. This posting ist not up to date anymore </strong> </p> <p>------------------------------------------------------<br /> It is not an April joke! I read frequently PHP-Magazine (http://php-mag.net http://php-mag.de), Yesterday I discovered some interesting things, because I was able, to read some source code and they are still publicly available. I don’t want to write, how I could read the source code, because there are always some people out side, who want play with it. Very important, they have <strong>register_globals on</strong>. I hope, they fix it as soon as possible.</p> <p><a href="http://www.pure-php.de/node/24">read more</a></p> http://www.pure-php.de/node/24#comment PHP Fri, 01 Apr 2005 09:59:12 +0200 pure-php 24 at http://www.pure-php.de include_once / require_once Wrapper Class optimized http://www.pure-php.de/node/22 <p>When I posted my Idea of building a wrapper class for include_once and require_once, I didn't think, that the many php developer would like it. But I was wrong, fortunately.</p> <p>Thanks to <a href="http://www.pure-php.de/node/19#comment-8">Mathias Taylor</a> for benchmarking. Special thanks goes to <a href="http://www.pure-php.de/node/19#comment-15">Cristian Strian</a> for his suggestion to optimize the class, and make it faster. That is the optimized wrapper class. </p> <p><strong>Usage:</strong><br /> <div class="codeblock"><code><span style="color: #000000"> <span style="color: #0000CC">&lt;?php<br /></span><span style="color: #006600">require(</span><span style="color: #CC0000">"includeWrapper.class.php"</span><span style="color: #006600">);<br /></span><span style="color: #0000CC">includeWrapper</span><span style="color: #006600">::</span><span style="color: #0000CC">includeOnce</span><span style="color: #006600">(</span><span style="color: #CC0000">"test.php"</span><span style="color: #006600">);<br /></span><span style="color: #0000CC">includeWrapper</span><span style="color: #006600">::</span><span style="color: #0000CC">includeOnce</span><span style="color: #006600">(</span><span style="color: #CC0000">"test.php"</span><span style="color: #006600">);<br /></span><span style="color: #0000CC">includeWrapper</span><span style="color: #006600">::</span><span style="color: #0000CC">includeOnce</span><span style="color: #006600">(</span><span style="color: #CC0000">"test.php"</span><span style="color: #006600">);<br /></span><span style="color: #0000CC">print_r</span><span style="color: #006600">(</span><span style="color: #0000CC">includeWrapper</span><span style="color: #006600">::</span><span style="color: #0000CC">getPaths</span><span style="color: #006600">());<br /></span><span style="color: #0000CC">?&gt;</span> </span> </code></div></p> <p><strong>Output:</strong><br /> Array<br /> (<br /> [test.php] =&gt; 1<br /> )</p> <p>The class itself.</p> <p><div class="codeblock"><code><span style="color: #000000"> <span style="color: #0000CC">&lt;?php<br /></span><span style="color: #006600">class&nbsp;</span><span style="color: #0000CC">includeWrapper</span><span style="color: #006600">{<br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;</span><span style="color: #0000CC">$paths&nbsp;</span><span style="color: #006600">=&nbsp;array();<br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;function&nbsp;</span><span style="color: #0000CC">includeOnce</span><span style="color: #006600">(</span><span style="color: #0000CC">$path_file</span><span style="color: #006600">){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!isset(</span><span style="color: #0000CC">self</span><span style="color: #006600">::</span><span style="color: #0000CC">$paths</span><span style="color: #006600">[</span><span style="color: #0000CC">$path_file</span><span style="color: #006600">])){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;include(</span><span style="color: #0000CC">$path_file</span><span style="color: #006600">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000CC">self</span><span style="color: #006600">::</span><span style="color: #0000CC">$paths</span><span style="color: #006600">[</span><span style="color: #0000CC">$path_file</span><span style="color: #006600">]&nbsp;=&nbsp;</span><span style="color: #0000CC">true</span><span style="color: #006600">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;static&nbsp;function&nbsp;</span><span style="color: #0000CC">requireOnce</span><span style="color: #006600">(</span><span style="color: #0000CC">$path_file</span><span style="color: #006600">){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!isset(</span><span style="color: #0000CC">self</span><span style="color: #006600">::</span><span style="color: #0000CC">$paths</span><span style="color: #006600">[</span><span style="color: #0000CC">$path_file</span><span style="color: #006600">])){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;require(</span><span style="color: #0000CC">$path_file</span><span style="color: #006600">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000CC">self</span><span style="color: #006600">::</span><span style="color: #0000CC">$paths</span><span style="color: #006600">[</span><span style="color: #0000CC">$path_file</span><span style="color: #006600">]&nbsp;=&nbsp;</span><span style="color: #0000CC">true</span><span style="color: #006600">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF9900">//&nbsp;just&nbsp;for&nbsp;testing<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #006600">public&nbsp;static&nbsp;function&nbsp;</span><span style="color: #0000CC">getPaths</span><span style="color: #006600">(){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000CC">self</span><span style="color: #006600">::</span><span style="color: #0000CC">$paths</span><span style="color: #006600">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /></span><span style="color: #0000CC">?&gt;</span> </span> </code></div></p> http://www.pure-php.de/node/22#comment PHP Fri, 25 Mar 2005 23:38:00 +0100 pure-php 22 at http://www.pure-php.de Fatal Error is the Fatal Error of PHP - How to avoid it http://www.pure-php.de/node/21 <p>One of the disadvantages of PHP, and one of the things I don't like about the php, is the fatal error, because there isn't any way to avoid it. Well PHP is actually thought to be used in web environment, therefor it is not so important, if your script causes a fatal error, then only the execution of the script for a single request would be terminated.</p> <p>In PHP command line apps, it is really fatal, if your app causes a fatal error, because you have to restart your app. Well you can avoid this, if you write your app very carefully. You should always use <strong>if(function_exists("a_func")) and if(method_exists("a_method"))</strong>. Now you can be pretty sure, that the script won't cause any fatal error.<br /> If you dynamically load third party modules in your app, you have a real problem, because the included module could cause a fatal error, your app would be terminated. There is on way to avoid it. Use <strong>call_user_func</strong>. You can replace in third party modules every function call and method call with call_user_func. For example.<br /> <div class="codeblock"><code><span style="color: #000000"> <span style="color: #0000CC">&lt;?php<br /></span><span style="color: #006600">function&nbsp;</span><span style="color: #0000CC">add</span><span style="color: #006600">(</span><span style="color: #0000CC">$a</span><span style="color: #006600">,</span><span style="color: #0000CC">$b</span><span style="color: #006600">){<br />&nbsp;echo&nbsp;</span><span style="color: #0000CC">$a</span><span style="color: #006600">+</span><span style="color: #0000CC">$b</span><span style="color: #006600">;<br />}<br /></span><span style="color: #FF9900">//&nbsp;call&nbsp;the&nbsp;function&nbsp;with&nbsp;a&nbsp;small&nbsp;mistake<br /></span><span style="color: #0000CC">ad</span><span style="color: #006600">(</span><span style="color: #0000CC">2</span><span style="color: #006600">,</span><span style="color: #0000CC">3</span><span style="color: #006600">);&nbsp;</span><span style="color: #FF9900">//&nbsp;causes&nbsp;a&nbsp;fatal&nbsp;error<br />//replace&nbsp;it&nbsp;with<br /></span><span style="color: #0000CC">call_user_func</span><span style="color: #006600">(</span><span style="color: #CC0000">"ad"</span><span style="color: #006600">,</span><span style="color: #0000CC">2</span><span style="color: #006600">,</span><span style="color: #0000CC">3</span><span style="color: #006600">);&nbsp;</span><span style="color: #FF9900">//&nbsp;causes&nbsp;a&nbsp;warning<br /></span><span style="color: #0000CC">?&gt;</span> </span> </code></div></p> http://www.pure-php.de/node/21#comment PHP Wed, 23 Mar 2005 14:42:00 +0100 pure-php 21 at http://www.pure-php.de PHP Command Line - Avoid several Instances of your App. http://www.pure-php.de/node/20 <p>Since PHP 4, you can also write command line apps in php. If you have a critical app, and you want to avoid several, or mor than one instance of your app, to run, you can use the following class. It works only on unix and linux operating sytems.</p> <p>Usage:<br /> <div class="codeblock"><code><span style="color: #000000"> <span style="color: #0000CC">&lt;?php<br />inlude</span><span style="color: #006600">(</span><span style="color: #CC0000">"ProcessHandler.class.php"</span><span style="color: #006600">);<br />if(</span><span style="color: #0000CC">ProcessHandler</span><span style="color: #006600">::</span><span style="color: #0000CC">isActive</span><span style="color: #006600">()){<br />&nbsp;&nbsp;&nbsp;die(</span><span style="color: #CC0000">"Already&nbsp;running!\n"</span><span style="color: #006600">);<br />}else{<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000CC">ProcessHandler</span><span style="color: #006600">::</span><span style="color: #0000CC">activate</span><span style="color: #006600">();<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #FF9900">//run&nbsp;my&nbsp;app<br /></span><span style="color: #006600">}<br /></span><span style="color: #0000CC">?&gt;</span> </span> </code></div></p> <p><a href="http://www.pure-php.de/node/20">read more</a></p> http://www.pure-php.de/node/20#comment PHP Tue, 22 Mar 2005 00:39:01 +0100 pure-php 20 at http://www.pure-php.de