|
<?php
/*
* Get Users IP service.
* Author: Jeffrey Hill
* Site: www.flash-db.com/remoting/
*/
class getIP
{
function getIP()
{
$this->methodTable = array(
"getIPAddress" => array(
"description" => "Returns a users IP address.",
"access" => "remote",
"arguments" => array () // nothing needed as input.
)
);
}
function getIPAddress() {
$ip;
if (getenv("HTTP_CLIENT_IP")) {
$ip = getenv("HTTP_CLIENT_IP");
} else if (getenv("HTTP_X_FORWARDED_FOR")) {
$ip = getenv("HTTP_X_FORWARDED_FOR");
} else if(getenv("REMOTE_ADDR")) {
$ip = getenv("REMOTE_ADDR");
} else {
$ip = "UNKNOWN";
}
return $ip;
}
}
?>
|
|
#include "NetServices.as"
#include "NetDebug.as"
// The following is example code for returning a users IP address.
// It also uses the IP2Country web service found: http://www.flash-db.com/services/?ID=37&sType=Location/Geography
myResult = new Object();
myResult.onResult = function(result){
ip_txt.text = result;
// This determines what country the user if from - comment out this line if wanted.
getLocationByIP(result);
}
myResult.onStatus = function(status){
trace("Error: " + status.description);
}
System.onStatus = myResult.onStatus;
// Create a connection to your gateway. Make sure to change the path to point to gateway.php on your server.
var conn = NetServices.createGatewayConnection("http:// Path To /gateway.php");
// Specify the service you want to use. In this case the getIP.php service file should be located in your service directory.
var myService = conn.getService("getIP", myResult);
// Call the service, returns the users IP address.
myService.getIPAddress();
// --------- Gets country based on IP --------
// http://www.flash-db.com/services/?ID=37&sType=Location/Geography
// create result handler for results and error messages.
serviceResult = new Object();
serviceResult.onResult = function(result){
country_txt.text = result;
}
function getLocationByIP(ip) {
// sets up the service.
var service = conn.getService("http://www.flash-db.com/services/ws/ip2Country.wsdl", serviceResult);
// Set the params and call the service. IP is passed as an argument to this function.
params = {
username:'anything',
password:'anything',
ip:ip
}
// calls the method.
service.getCountryByIP(params);
}
|