Problems with file_get_contents()....

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Pheddy
    New Member
    • Dec 2008
    • 80

    Problems with file_get_contents()....

    Hey i tried this code to get the country and IP via PHP (from: http://roshanbh.com.np/2008/07/getti...ss-in-php.html)
    [code=php]
    function countryCityFrom IP($ipAddr)
    {
    //function to find country and city from IP address
    //Developed by Roshan Bhattarai http://roshanbh.com.np

    //verify the IP address for the
    ip2long($ipAddr )== -1 || ip2long($ipAddr ) === false ? trigger_error(" Invalid IP", E_USER_ERROR) : "";
    $ipDetail=array (); //initialize a blank array

    //get the XML result from hostip.info
    $xml = file_get_conten ts("http://api.hostip.info/?ip=".$ipAddr);

    //get the city name inside the node <gml:name> and </gml:name>
    preg_match("@<H ostip>(\s)*<gml :name>(.*?)</gml:name>@si",$ xml,$match);

    //assing the city name to the array
    $ipDetail['city']=$match[2];

    //get the country name inside the node <countryName> and </countryName>
    preg_match("@<c ountryName>(.*? )</countryName>@si ",$xml,$matches );

    //assign the country name to the $ipDetail array
    $ipDetail['country']=$matches[1];

    //get the country name inside the node <countryName> and </countryName>
    preg_match("@<c ountryAbbrev>(. *?)</countryAbbrev>@ si",$xml,$cc_ma tch);
    $ipDetail['country_code']=$cc_match[1]; //assing the country code to array

    //return the array containing city, country and country code
    return $ipDetail;

    }

    $IPDetail=count ryCityFromIP('1 2.215.42.19');
    echo $IPDetail['country']; //country of that IP address
    echo $IPDetail['city']; //outputs the IP detail of the city[/code]

    ..But Apaches says
    ERROR: Fatal error: Call to undefined function: file_get_conten ts() in c:\apache\htdoc s\test_pages\br owser_getipandc ountry.php on line 13

    Seems to get this everytime i use file_get_conten ts().. Any idea here?

    Thanks again!
    Frederik
    Last edited by Atli; Jun 1 '09, 12:17 PM. Reason: Added [code] tags.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    That's weird. The file_get_conten ts function is a part of the PHP core. It should always be available.

    Which version of PHP are you using?
    Did you set this server up yourself, or are you using a host?
    Did you perhaps build PHP yourself?
    Last edited by Atli; Jun 2 '09, 08:37 PM. Reason: Typo. (I'ts my keyboard, I swear. It's possessed!)

    Comment

    • Pheddy
      New Member
      • Dec 2008
      • 80

      #3
      I am fairly new to PHP and use the easy setup PHPTriad 2.2.. Developer says it uses the most updated version of PHP..

      I have copied the code exactly like it is discribed in post. Since I can free myself for noob writings :D then it must be the php version or?

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        I've never heard of PHPTriad before, but the sourceforge site says it is in beta.
        Perhaps there are some bugs lurking around in it that are causing this issue.

        You might want to try a more mature installer, like XAMP.

        Comment

        • Pheddy
          New Member
          • Dec 2008
          • 80

          #5
          PHPTriad 2.2 was the problem it is now fixed with XAMP...
          Thanks for your reply!

          Frederik

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            Glad I could be of help :)
            See you around.

            Comment

            • Markus
              Recognized Expert Expert
              • Jun 2007
              • 6092

              #7
              It was last updated in 2002.. that should be a slight give away ;)

              Comment

              Working...