IP2Currency: PHP Sample Code

The sample code below provide you an example on how to obtain the latest currency exchange rate and the homeland currency by visitor's IP address.


<!--
//////////////////////////////////////////////////////////////////////////////////
//
//  This source code is only licensed to our premium subscribers. It is provided "as is" and without warranties.
//
//  http://www.fraudlabs.com © All Rights Reserved 2012
///
/////////////////////////////////////////////////////////////////////////////////
-->
<html>
	<head>
		<title>IP2Currency Web Service Sample Codes for PHP</title>
	</head>
	<form action="" method="post">
<br>
Visitor IP Address: <input type="text" name="visitorip" value="68.142.197.65" /> <br>
From Currency Code: <input type="text" name="fromcurrencycode" value="CAD" /> <br>
To Currency Code: <input type="text" name="tocurrencycode" value="" /> <br>
From Amount: <input type="text" name="fromamount" value="" /> <br>
License Key: <input type="text" name="license" value="<Enter License Key>" /> <br>
<br>

<input type="submit" name="submit" />
</form>
<body>
<?php
if (!isset($_POST['submit'])) {} // if page is not submitted to itself echo the form
else
{
	$visitorip = $_POST["visitorip"];
	$fromcurrencycode = $_POST["fromcurrencycode"];
	$tocurrencycode = $_POST["tocurrencycode"];
	$fromamount = $_POST["fromamount"];
	$license = $_POST["license"]; 

	if ($license == "<Enter License Key>" || $license == "")
	{
		echo "license key is a required field." ;
	}
	else	
	{
		$wsdl = "http://v1.fraudlabs.com/ip2currencywebservice.asmx?wsdl";

		// There are 2 method of getting the results, one using PHP SOAP Client and another using NuSOAP Client. //
		// Just uncomment your preferred method and run the code.                                                //

		/* Method 1: Using PHP SOAP Client */

		$client = new SoapClient($wsdl);
		$parms = array("VISITORIP" => $visitorip,"FROMCURRENCYCODE" => $fromcurrencycode,"TOCURRENCYCODE" => $tocurrencycode,"FROMAMOUNT" => $fromamount,"LICENSE" => $license);

		$result = $client->IP2Currency($parms);

		echo "FROMCURRENCYCODE = " . $result->FROMCURRENCYCODE . "<br>";
		echo "TOCURRENCYCODE = " . $result->TOCURRENCYCODE . "<br>";
		echo "TOCURRENCYSYMBOL = " . $result->TOCURRENCYSYMBOL . "<br>";
		echo "FROMAMOUNT = " . $result->FROMAMOUNT . "<br>";
		echo "TOAMOUNT = " . $result->TOAMOUNT . "<br>";
		echo "CONVERSIONRATE = " . $result->CONVERSIONRATE . "<br>";
		echo "TOCOUNTRYNAME = " . $result->TOCOUNTRYNAME . "<br>";
		echo "TOCOUNTRYCODE = " . $result->TOCOUNTRYCODE . "<br>";
		echo "CREDITSAVAILABLE = " . $result->CREDITSAVAILABLE . "<br>";
		echo "MESSAGE = " . $result->MESSAGE . "<br>";
		/* end of Method 1 */

		/* Method 2: Using NuSOAP Client */
		/*
		require_once('NuSOAP/nusoap.php');

		$client = new nusoap_client($wsdl, 'wsdl');

		$parms = array(array("VISITORIP" => $visitorip,"FROMCURRENCYCODE" => $fromcurrencycode,"TOCURRENCYCODE" => $tocurrencycode,"FROMAMOUNT" => $fromamount,"LICENSE" => $license));

		$result = $client->call('IP2Currency', $parms);

		echo "FROMCURRENCYCODE = " . $result["FROMCURRENCYCODE"] . "<br>";
		echo "TOCURRENCYCODE = " . $result["TOCURRENCYCODE"] . "<br>";
		echo "TOCURRENCYSYMBOL = " . $result["TOCURRENCYSYMBOL"] . "<br>";
		echo "FROMAMOUNT = " . $result["FROMAMOUNT"] . "<br>";
		echo "TOAMOUNT = " . $result["TOAMOUNT"] . "<br>";
		echo "CONVERSIONRATE = " . $result["CONVERSIONRATE"] . "<br>";
		echo "TOCOUNTRYNAME = " . $result["TOCOUNTRYNAME"] . "<br>";
		echo "TOCOUNTRYCODE = " . $result["TOCOUNTRYCODE"] . "<br>";
		echo "CREDITSAVAILABLE = " . $result["CREDITSAVAILABLE"] . "<br>";
		echo "MESSAGE = " . $result["MESSAGE"] . "<br>";
		*/
		/* end of Method 2 */
	}
}
?>

Download the source code
You need a license key for the solution. And, it is free and available at IP2Currency Free License