Search:
Main Menu
Login | RSS |

Quick PHP Code Tips and Examples

PHP Programming Tips, Tutorials and Source Code Examples for newbie

PHP: Currency Exchange using XML-RPC client

May 11th, 2007 by Jon Moffet

This is an example PHP code I wrote to demonstrate how to connect to Foxrate Currency Exchange server and retrieve the latest exchange rate.

The example uses The Incutio XML-RPC for PHP library. Please visit refer to Incutio XML-RPC Library Manual for further in-depth reference.

PHP:
  1. require('IXR.inc.php');
  2.  
  3. // connect to foxrate.org currency exchange server
  4. $client = new IXR_Client('http://foxrate.org/rpc/');
  5.  
  6. //make the currency exchange
  7. if (!$client->query('foxrate.currencyConvert', 'USD', 'GBP',1000)) {
  8.     die('Error detected - '.$client->getErrorCode().' : '.$client->getErrorMessage());
  9. }
  10.  
  11. $response = $client->getResponse();
  12. echo "USD1000  is currently equal to GBP " . $response['amount'];

The demo shows you how to get the current value of USD 1000 in British Pound (GBP). Hopefully this example will be useful for you to build a working currency exchage webapp using foxrate.org api

Download the sample code here : foxrate_rpc_1.zip

Tags: , , , , , ,

Posted in Uncategorized | 1 Comment »

OpenTracker - Lean and mean PHP Bittorrent Tracker

May 10th, 2007 by Jon Moffet

Opentracker is the most simple php bittorrent tracker that I came across. It only requires a single MySQL table to function and it is a fully compliant bittorrent tracker as outlined by Bram Cohen.

I've included Opentracker in this blog because of its simplicity that made it easy to be use as a reference implementation for your own home-brew tracker.

Download Opentracker

  1. opentracker.zip (local)
  2. opentracker.zip (mirror)

Important Notice Due remember that MySQL based bittorrent trackers are known to use many connections at the same time, and may cause your database server to choke in a shared hosting environment. You've been warned!

Tags: , , , , ,

Posted in Uncategorized | No Comments »

Spam Protected Contact Form example (using Akismet)

May 9th, 2007 by Jon Moffet

This is an example of an enhanced contact form previously featured here and here . I've improved the contact form example to include Akismet spam protection in order to make it more resistant to spam attack.

Demonstration

plain_akismet.jpg

The example includes :

  • PHPMailer class for sending mail through your own SMTP server
  • Akismet Anti-spam class
  • Table-less contact form

Feel free to download the example to be used in your own application : plain_akismet.zip

Tags: , , , , , , ,

Posted in Uncategorized | 2 Comments »

How to switch to PHP5 in Cpanel based web hosting

May 9th, 2007 by Jon Moffet

Some web hosting provider such as e-ruang offers choices of using PHP4 or or PHP5 in their hosting. To avoid conflict with existing scripts, they will usually offer PHP 4 by default.

But for obvious reasons, you may want to use PHP5 as it supports more functionalities and more robust than PHP4. To enable PHP5 for your account, you need to create a .htaccess file containing :

CODE:
  1. AddHandler application/x-httpd-php5 .php .php4 .php3 .phtml

Save the .htaccess file, and upload it to the root directory of your server.

Then upload a php file containing phpinfo() function to test whether PHP5 has been enabled or not. If the modification has not been successful then you should contact your web hosting provider and ask about the appropriate way to activate PHP5 functionality.

Tags: , , ,

Posted in Uncategorized | No Comments »

Using SQLite in PHP 5

May 9th, 2007 by Jon Moffet

Here is a well-written step-by-step tutorial on how to use SQLite in PHP 5. The tutorial was written by Ilia Alshanetsky and featured in Zend Developer Zone.

SQLite Introduction

For those who don't know, SQLite is a lightweight embedded database management system, it is available as the default database engine for PHP5. Due to its embedded nature, SQLite store its database on a single file and is significantly faster than MySQL. Backing up SQLite database is as simple as copying its database file to a backup media.

SQLite is an excellent choice for creating and deploying portable web application without the need to do complex db setups on target machines.

Tags: , ,

Posted in Uncategorized | 1 Comment »

« Previous Entries Next Entries »