Get Website Lowest price!

Wordpress Experts!

×

php up to date

24 Cool PHP Libraries You Should Know About


PHP different type of  Validation  you should know


Automatic redirect mobile website from normal website when view in the mobile

/* Change path info depending on your file locations */

 require_once 'Mobile_Detect.php'; $detect = new Mobile_Detect; if($detect->isMobile()) 
{ header('Location: http://mobile.example1.com/'); exit; } 

24 Cool PHP Libraries click here

Getting User IP Address


$ip = getenv("REMOTE_ADDR") ; 
Echo "Your IP is " . $ip;


Getting User Location based on IP

$ip = getenv("REMOTE_ADDR") ; 
Echo "Your IP is " . $ip;
       print_r(geoCheckIP($ip));
     

       //Get an array with geoip-infodata
       function geoCheckIP($ip)
       {
               //check, if the provided ip is valid
               if(!filter_var($ip, FILTER_VALIDATE_IP))
               {
                       throw new InvalidArgumentException("IP is not valid");
               }

               //contact ip-server
               $response=@file_get_contents('http://www.netip.de/search?query='.$ip);
               if (empty($response))
               {
                       throw new InvalidArgumentException("Error contacting Geo-IP-Server");
               }

               //Array containing all regex-patterns necessary to extract ip-geoinfo from page
               $patterns=array();
               $patterns["domain"] = '#Domain: (.*?) #i';
               $patterns["country"] = '#Country: (.*?) #i';
               $patterns["state"] = '#State/Region: (.*?)<br#i';
               $patterns["town"] = '#City: (.*?)<br#i';

               //Array where results will be stored
               $ipInfo=array();

               //check response from ipserver for above patterns
               foreach ($patterns as $key => $pattern)
               {
                       //store the result in array
                       $ipInfo[$key] = preg_match($pattern,$response,$value) && !empty($value[1]) ? $value[1] : 'not found';
               }

               return $ipInfo;

       }
SHARE

mani kandan

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment