473,385 Members | 1,869 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Problems with file_get_contents()....

80
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)
Expand|Select|Wrap|Line Numbers
  1. function countryCityFromIP($ipAddr)
  2. {
  3. //function to find country and city from IP address
  4. //Developed by Roshan Bhattarai http://roshanbh.com.np
  5.  
  6. //verify the IP address for the
  7. ip2long($ipAddr)== -1 || ip2long($ipAddr) === false ? trigger_error("Invalid IP", E_USER_ERROR) : "";
  8. $ipDetail=array(); //initialize a blank array
  9.  
  10. //get the XML result from hostip.info
  11. $xml = file_get_contents("http://api.hostip.info/?ip=".$ipAddr);
  12.  
  13. //get the city name inside the node <gml:name> and </gml:name>
  14. preg_match("@<Hostip>(\s)*<gml:name>(.*?)</gml:name>@si",$xml,$match);
  15.  
  16. //assing the city name to the array
  17. $ipDetail['city']=$match[2]; 
  18.  
  19. //get the country name inside the node <countryName> and </countryName>
  20. preg_match("@<countryName>(.*?)</countryName>@si",$xml,$matches);
  21.  
  22. //assign the country name to the $ipDetail array
  23. $ipDetail['country']=$matches[1];
  24.  
  25. //get the country name inside the node <countryName> and </countryName>
  26. preg_match("@<countryAbbrev>(.*?)</countryAbbrev>@si",$xml,$cc_match);
  27. $ipDetail['country_code']=$cc_match[1]; //assing the country code to array
  28.  
  29. //return the array containing city, country and country code
  30. return $ipDetail;
  31.  
  32. }
  33.  
  34. $IPDetail=countryCityFromIP('12.215.42.19'); 
  35. echo $IPDetail['country']; //country of that IP address 
  36. echo $IPDetail['city']; //outputs the IP detail of the city
..But Apaches says
ERROR: Fatal error: Call to undefined function: file_get_contents() in c:\apache\htdocs\test_pages\browser_getipandcountr y.php on line 13

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

Thanks again!
Frederik
Jun 1 '09 #1
6 3619
Atli
5,058 Expert 4TB
Hi.

That's weird. The file_get_contents 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?
Jun 1 '09 #2
Pheddy
80
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?
Jun 1 '09 #3
Atli
5,058 Expert 4TB
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.
Jun 1 '09 #4
Pheddy
80
PHPTriad 2.2 was the problem it is now fixed with XAMP...
Thanks for your reply!

Frederik
Jun 2 '09 #5
Atli
5,058 Expert 4TB
Glad I could be of help :)
See you around.
Jun 2 '09 #6
Markus
6,050 Expert 4TB
It was last updated in 2002.. that should be a slight give away ;)
Jun 3 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Rob | last post by:
for some reason i keep getting : Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in /home/rob/www/php/filegetcontents2.php on...
2
by: ggg | last post by:
Here's what I'm trying to do. The server serves up XML documents based on what I specify in the GET string. This is on a server I have no control over. There is a lag between the time when I...
3
by: Csaba Gabor | last post by:
I've got a section of code that takes a user supplied $url and essentially does: function redirectRequest($url) { $resultRemote = @file_get_contents($url); return $resultRemote; } Is there a...
1
by: jjainschigg | last post by:
I'm running PHP 5 on a shared VPS. I have a couple little apps that are using file_get_contents() and readfile() for various kinds of (what should be) low-overhead, fast outbound accesses ... that...
5
by: howa | last post by:
are there any advantage in replacing all fread() operations with file_get_contents() ? i.e. file_get_contents("/usr/local/something.txt") VS $filename = "/usr/local/something.txt";
4
by: Aetherweb | last post by:
This is probably really obvious, sorry, been a long day... I'm wanting to create a PHP file which is a template for an email, and read the file into a string, ready to send out using my email...
9
by: howa | last post by:
Target: To fetch a file using PHP and send to user Method 1: echo file_get_contents( $file_path ); Method 2: readfile( $file_path );
6
by: Taras_96 | last post by:
Hi everyone, The output of echo file_get_contents("http://watchout4snakes.com/creativitytools/ RandomWord/RandomWordPlus.aspx"); leaves the browser empty.. no error messages, nothing. ...
0
by: pac1250 | last post by:
Hi, I am searching how to solve a problem and I dont find it :( I want to access a page from a script behind a proxy : (my script) <-(a proxy with authentification) <-(https serveur with...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.