473,947 Members | 5,336 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems with file_get_conten ts()....

80 New Member
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_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
Jun 1 '09 #1
6 3646
Atli
5,058 Recognized Expert Expert
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?
Jun 1 '09 #2
Pheddy
80 New Member
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 Recognized Expert Expert
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 New Member
PHPTriad 2.2 was the problem it is now fixed with XAMP...
Thanks for your reply!

Frederik
Jun 2 '09 #5
Atli
5,058 Recognized Expert Expert
Glad I could be of help :)
See you around.
Jun 2 '09 #6
Markus
6,050 Recognized Expert Expert
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
4223
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 line 3 Warning: file_get_contents(http://folding.stanford.edu/teamstats/team92.txt): failed to open stream: Resource temporarily unavailable in /home/rob/www/php/filegetcontents2.php on line 3
2
2211
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 issue the GET request, and when I actually get the response. (I suspect because the server has to dig for the data and format it. In any case, it's longer than say, a simple HTML page request to the web server.) When I manually cut and paste the...
3
2687
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 reasonable way to trap for and differentiate between the major (most common) types of failure? For example, common scenarios in which I would not get back a desired
1
5076
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 is, I'm handing URLencoded arguments to a couple fast servers and grabbing small patches of XML in return. When I enter these URL+argument strings in a browser (with the caches turned off), I get effectively instant responses -- so the remote...
5
23055
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
2755
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 functions... but I want to be able to get the PHP file to be server processed so that its content is created on the fly. Eg in pseudo code, what I want to do is this: 1$email_param1 = "my email param 1";
9
21022
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
6962
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. Why is this occurring?
0
5029
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 authentification) -----------------------------------------------------------------
0
9982
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11155
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10690
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7429
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6113
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6331
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4945
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4537
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3541
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.