function getClientIP () {
if (isset ($_SERVER ['HTTP_X_FORWARDED_FOR'])){
$clientIP = $_SERVER ['HTTP_X_FORWARDED_FOR'];
}elseif (isset ($_SERVER ['HTTP_X_REAL_IP'])){
$clientIP = $_SERVER ['HTTP_X_REAL_IP'];
}else {
$clientIP = $_SERVER['REMOTE_ADDR'];
}
return $clientIP;
}
Also we can use following API method
<?php
echo getClientIp();
function getClientIp()
{
$env = 'prod';
if($env == 'prod' ){
$url = "http://jsonip.com/";
$curlData =Ipcurl($url);
$sttus = explode("||",$curlData);
if($sttus[1]==200)
$xmlData_ip = $sttus[0];
$ipPasrse = explode(",",$xmlData_ip);
if($ipPasrse[0]!="")
$ipGet = explode(":",$ipPasrse[0]);
if($ipGet[1]!="")
$ipAddress = str_replace('"',"",$ipGet[1]);
}
return $ipAddress ;
}
function Ipcurl( $url, $cookiefile = '', $pmSSL = FALSE, $pmCert = FALSE)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if($pmSSL == TRUE){
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,$pmCert); // You should be able to set this to TRUE if your SSL certificate
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,TRUE);
}
$result = curl_exec($ch);
$info = curl_getinfo ($ch);
if (curl_errno($ch)) {
$error = curl_error($ch);
}
curl_close($ch);
return $result.'||'.$info['http_code'];
}
?>
No comments:
Post a Comment