Lightweight, but Powerful PHP5 XML-RPC Server

I have written a XML-Server in PHP5.
It is very easy to use. Just include the file and run the server.
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)
Example

<?php
$ws 
= new XML_RPC_Server();
$ws->registerFunction('getTime');
$ws->registerMethod('Product::getPrice');
$ws->registerMethod('Product::getDetail');
$ws->registerMethod('Product::getBinaryPicture');
$ws->run();
?>

Example Source,
http://www.pure-php.com/php/service.source.php
The Server
http://www.pure-php.com/php/xmlrpc.php.txt

add new comment | read more

PHP Style Cookie and Get Parameters in JavaScript

For lazy phpers, with this function you can read cookies and get parameters in javascript in php style.
(I use php tags to highlight the code)
Example

<?php
populateRequest
();
if( 
$_COOKIE['sid'] ) {
// do something
}
if( 
$_GET['cmd'] == 'login' ) {
// do something
}
?>

add new comment | read more

Java Class Search with Ajax, powered by PHP

Pure-java.com search for java classes with use of ajax. The site is powered by PHP5

add new comment

The easist way to avoid double clicks in submit buttons

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.

With this JavaScript class, you deactivate this. Just put that and end of your site.

function ClickObServer(){
this.deactivateDoubleClicks = function() {
this.checkClicks(document.getElementsByTagName("a"));
this.checkClicks(document.getElementsByTagName("input"));
}
this.checkClicks = function ( el ){
for (var i = 0; i < el.length; i++) {

add new comment | read more

Pure PHP up again

After several months pure-php is up agian, and I would try to post in the next days

1 comment

PHP-Magazine's security leak closed

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.

The user of Powersalve can ask me for a quick solution. The can also ask the company behind Powerslave.

add new comment

Security matters, specially for PHP-Magazine, some source code publicly accessible!


PHP-Magazine has fixed this secutrity leak, it is not possible to read any source code. This posting ist not up to date anymore

------------------------------------------------------
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 register_globals on. I hope, they fix it as soon as possible.

add new comment | read more

include_once / require_once Wrapper Class optimized

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.

Thanks to Mathias Taylor for benchmarking. Special thanks goes to Cristian Strian for his suggestion to optimize the class, and make it faster. That is the optimized wrapper class.

Usage:

<?php
require("includeWrapper.class.php");
includeWrapper::includeOnce("test.php");
includeWrapper::includeOnce("test.php");
includeWrapper::includeOnce("test.php");
print_r(includeWrapper::getPaths());
?>

Output:
Array
(
[test.php] => 1
)

The class itself.

<?php
class includeWrapper{
    public static 
$paths = array();
    public static function 
includeOnce($path_file){
        if(!isset(
self::$paths[$path_file])){
            include(
$path_file);
            
self::$paths[$path_file] = true;
        }
    }
    public static function 
requireOnce($path_file){
        if(!isset(
self::$paths[$path_file])){
            require(
$path_file);
            
self::$paths[$path_file] = true;
        }
    }
    
// just for testing
    
public static function getPaths(){
        return 
self::$paths;
    }
}
?>

2 comments

Fatal Error is the Fatal Error of PHP - How to avoid it

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.

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 if(function_exists("a_func")) and if(method_exists("a_method")). Now you can be pretty sure, that the script won't cause any fatal error.
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 call_user_func. You can replace in third party modules every function call and method call with call_user_func. For example.

<?php
function add($a,$b){
 echo 
$a+$b;
}
// call the function with a small mistake
ad(2,3); // causes a fatal error
//replace it with
call_user_func("ad",2,3); // causes a warning
?>

add new comment

PHP Command Line - Avoid several Instances of your App.

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.

Usage:

<?php
inlude
("ProcessHandler.class.php");
if(
ProcessHandler::isActive()){
   die(
"Already running!\n");
}else{
   
ProcessHandler::activate();
   
//run my app
}
?>

3 comments | read more

Datenschutz | Impressum