Posts Tagged ‘php’

XML-RPC in PHP :: FoXRate Currency Exchange API

Wednesday, October 21st, 2009

Today my friend Sakib was looking for a Currency Exchange API to implement it on one of his projects. So, I decided to write this small PHP code snippet for him. I hope this will help him and also other developers. Because, XML-RPC section of the PHP Manual is still incomplete :( .

<?php

/*
* Reference :: http://foxrate.org/
* 
* For $from and $to :: http://www.oanda.com/site/help/iso_code.shtml
*/

function getExchangeRate($from = 'USD', $to = 'BDT', $ammount = 1.0) {
    
    $ammount = doubleval($ammount);
    $request = xmlrpc_encode_request("foxrate.currencyConvert", array($from, $to, $ammount));

    $stream = stream_context_create(array('http' => array(
        'method' => "POST",
        'header' => "Content-Type: text/xml\r\nUser-Agent: xmlrpclib.py/1.0  1 (by www.pythonware.com)\r\nHost: foxrate.org\r\n",
        'content' => $request
    )));

    $endpoint = "http://foxrate.org/rpc/";
    $file = file_get_contents($endpoint, false, $stream);
    $response = xmlrpc_decode($file);

    if (is_array($response) && xmlrpc_is_fault($response)) :
        return 'error';
    else :
        return $response;
    endif;
}

print_r(getExchangeRate());

?>

Captcha Breaking Experiment in PHP

Thursday, January 8th, 2009

Few days back I saw a really nice post of Nadim Jahangir about breaking captcha [Breaking CAPTCHA: Getting Naughty With Computer Vision Based Human Interaction Simulator Bot]. After, reading his post, I’d decided to create something similar with PHP. And I’ve already done it. I also use somewhereindhaka.net captcha for my experiment but didn’t create any bot to post in their site ;) .

Breaking Captcha with Histogram in PHP

Steps are very simple -

  1. Create horizontal & vertical histogram of captcha using PHP GD.
  2. Recognize each character by comparing values from histogram.
  3. I didn’t use any Template Recognition Algorithm. Rather, I use simple Edit Distance Algorithm (Levenshtein Distance). And it works :)

See it live – http://tr.im/35au