Categories Archives

You are currently viewing all posts published under Code Projects.


From some of my posts you’d figure I had a big project, where many problems occurred between SOAP PHP and other services..yeah it happened.

I had to implement connections with various security protocols, the other day at StackOverflow I noticed someone having problem with this, and most of the posts have no responses at all.

This specific post will show you to establish a connection to a SOAP WebService that is secured with WSSE, the specific doc is Web Services Security Username Token Profile:

In order to structure it clearly, and make sure PHP doens’t f*ck while generating the XML, we create various classes.

First we need a Class to store our username and password.

Then we need a class to store our Username Token related to this service.

Now instead of extending the SoapClient, which made errors happened in other places of communication with various other SOAP APIs.

I just make client inside another class, with the security options prepared and then return it to be used elsewhere in the code.

I have trace, exceptions and connection_timeout activated which are all optional.

After all those 3 classes are created, I can just access my prepared client like this:

Obvious as it seems, you need to indicate your user, pw, wsdl and gate (optional) to connect.

Afterwards you use it just as normal, example:

Hope this comes in handy for some of you..
Happy coding!

PHP snippet to Watermark Images Automatically.

This snippet brings a one line .htaccess, if you choose to use it, any call to a image on your website, gets automatically watermarked, stopping anyone from downloading the image without the watermark.

You can also center the watermark in the following ‘variable name‘ positions:


You can either change the default settings in the .php file, or if you invoke the script direct directly you can pass parameters either in .htaccess or in a html page, as you can see in the demo.

The scripts uses two merging type functions (imagecopy and imagecopymerge).
In case you already have a .PNG or .GIF with the opacity set, you can set the script to just overlay it, otherwise if you use a JPEG or any other file without transparency set, you can choose the opacity and the script will merge it accordingly.

You can find the code over at github. You can find a Demo here.


PHP class to calculate a Team based ELO Rating System for 5 vs 5.

This is heavily inspired on:

  • Heroes of Newerth
  • League of Legends
  • DotA 2

The use of this class is quite simple.
You can find the code over at github which has a usage example. You can find a demo here.

But simply, this takes two team arrays, with a mandatory elo column.
The class will then calculate both team averages, win rate probabilitys.
And when you execute the calculate function it will return the same two arrays with two new columns, containing the ‘gain’ and ‘loss’ points for each case.
You can use them as you wish.