Jump to content
Larry Ullman's Book Forums

Geoip With Pear


Recommended Posts

Hello,

 

I just wondered if anyone had experienced a similar problem that I have with PEAR during Larry's example. I have installed the package from PEAR for IP Geolocation, except my package doesnt include a file called Geo.php. It does however include a GeoIP file, which I have tried to use in place of the Geo.php. However running Larry's script (from his folder) through that (just so I knew it wasnt a type error on my part, or at least hoped it wasnt!!)) I get the following error:

 

"Call to private method Net_GeoIP::getRecord() from context"

 

- I know what the error means thanks to the previous chapters and I have tried making the methods public, but this in turn sprung up more errors.

 

I did also try and use the GEO_IP (beta) package but that was also unfortuantely to no avail.

 

I wondered if anyone else had experienced a similar problem, or new of a fix??

 

Here is my code for the file, just in case it is my error:

require_once('C:\Documents and Settings\Simon\My Documents\Microbiology\xampp\php\PEAR\Net\GeoIP.php');

 

// Create the object

$net_geo = new Net_GeoIP();

 

// Get the clients IP address

$ip = $_SERVER['REMOTE_ADDR'];

 

// Get the information

$results = $net_geo->getRecord($ip);

 

// Print whatever about the user

echo "<p>Our spies tell us the following information about you:<br />

IP Address: $ip<br />

Country: {$results['COUNTRY']}<br />

City, State: {$results['CITY']}, {$results['STATE']}<br />

latitude: {$results['LAT']}<br />

Longitude: {$results['LONG']}</p>";

 

// Print something about a site:

$url = 'www.apple.com';

 

// Get the IP address

$ip = gethostbyname($url);

 

// Get the information

$results = $net_geo->getRecords($ip);

 

// Print whatever about the url

echo "<p>Our spies tell us the following information about the URL $url:<br />

IP Address: $ip<br />

Country: {$results['COUNTRY']}<br />

City, State: {$results['CITY']}, {$results['STATE']}<br />";

 

?>

Link to comment
Share on other sites

Hi Larry,

 

I've just added my signature to my posts. Sorry i forgot to yesterday.

 

I'm using GeoIP.php,v 1.3 2006/06/07

I'm using PHP 5.3.1

And i used the pear command installer through xampp to get the package using

pear install Net_Geo

 

 

 

I've actually just updated my PEAR package to 1.9.2 and thought, maybe I should try to upgrade my Net_Geo too and hope it works, but this failed:

 

"Could not extract the package.xml file, this goes on to say couldn't create directory, unable to create path and then finally, Download of "pear/Net_Geo succeeded but it is not a valid package archive.

 

But in my Net folder download the only files provided were GeoIP.php, SMTP.php and Socket.php so there was no Geo.php that was is referenced in the book. I do have a Geo.php but it is within a Zend folder that came (I think) with xampp. I have had a look over this file too, but couldn't get that to work i'm afraid.

 

Thanks for the reply,

 

I like the enw forum too

 

Jonathon

Link to comment
Share on other sites

Hey Jonathon,

 

Thanks for the words on the forum. As for Net_Geo, I'm a little confused. There's Net_Geo, which I used in the book, whose current version is 1.0.5. And there's Net_GeoIP, whose current version is 1.0.0RC3 (beta). Based upon the directory structure you originally indicated (Net/GeoIP.php), it looks like you installed Net_GeoIP, although I'm not sure where you get version 1.3 and that 2006 date from. Based upon the directory structure you indicate in this follow up post (Net/Geo.php), that's Net_Geo. So the first thing you'll need to do is pick one and go with it. If you want to match the book's instructions, use Net_Geo. If you want to use Net_GeoIP, see the PEAR documentation for that class.

Link to comment
Share on other sites

Hi Larry,

 

Thanks for getting back to me. To clarify what i did. I downloaded the Net_Geo, except I had probelems with it. So I also tried Net_GeoIP to no avail. SO.... I started again. Deleted both the folders and tried to download Net_Geo using the pear installer within xampps shell. This failed, regarding the package.xml message referenced in my earlier reply. So I went in manually to my downloads and extracted the files and put them inside the Net folder. So I do have Geo.php now and it seems to be the right one.

 

However my Country,City,State,Lat,Long are all blank when I try to access an IP. The IP is being passed through ok and i've looked into the Geo.php file itself to try and see if there is anything I think that could be causing it. I can't see anything and it doesn't error.

 

Would you be able to add any expertise when it comes to debugging?

 

Thanks

 

Ps - looking forward to your js book

 

- To update this post. I've looked into my pear set up and I have done something to it that has rendered it pretty useless for installing packages. I'm getting a new one in the next couple months so I shall install pear again and fix it. Thanks for your help though. :)

Link to comment
Share on other sites

Hey Jonathon,

 

So, based upon your postscript, do you still need some help with this or no?

 

No thank you Larry,

 

I will tackle this in the next couple of months once i've moved and got my new computer all sorted. thanks for the help previously though.

Link to comment
Share on other sites

  • 3 months later...

Hi I am also having a problem with the PEAR Net_Geo package, I have been able to install it fine, I have version 1.0.5 which is supposed to be compatible with PHP 4.0.0 and above I also have the required dependencies so, in theory it should work, however, I seem to get a page full of errors and all the fields that should be filled in are blank apart from the IP address, as follows

 

Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in G:\xampp\php\PEAR\Net\Geo.php on line 449

Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in G:\xampp\php\PEAR\Cache\Container\file.php on line 130

Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in G:\xampp\php\PEAR\Cache\Container.php on line 364

Strict Standards: Only variables should be assigned by reference in G:\xampp\php\PEAR\Net\Geo.php on line 561

Notice: Undefined variable: text in G:\xampp\php\PEAR\Net\Geo.php on line 721

Notice: Undefined index: COUNTRY in G:\xampp\htdocs\php5advancedlu\ch_09\net_geo.php on line 40

Notice: Undefined index: CITY in G:\xampp\htdocs\php5advancedlu\ch_09\net_geo.php on line 41

Notice: Undefined index: STATE in G:\xampp\htdocs\php5advancedlu\ch_09\net_geo.php on line 41

Notice: Undefined index: LAT in G:\xampp\htdocs\php5advancedlu\ch_09\net_geo.php on line 42

Notice: Undefined index: LONG in G:\xampp\htdocs\php5advancedlu\ch_09\net_geo.php on line 43

Our spies tell us the following information about you:
IP Address: 127.0.0.1
Country:
City, State: ,
Latitude:
Longitude:

Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in G:\xampp\php\PEAR\Net\Geo.php on line 449

Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in G:\xampp\php\PEAR\Cache\Container\file.php on line 130

Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in G:\xampp\php\PEAR\Cache\Container.php on line 364

Strict Standards: Only variables should be assigned by reference in G:\xampp\php\PEAR\Net\Geo.php on line 561

Notice: Undefined variable: text in G:\xampp\php\PEAR\Net\Geo.php on line 721

Notice: Undefined index: COUNTRY in G:\xampp\htdocs\php5advancedlu\ch_09\net_geo.php on line 57

Notice: Undefined index: CITY in G:\xampp\htdocs\php5advancedlu\ch_09\net_geo.php on line 58

Notice: Undefined index: STATE in G:\xampp\htdocs\php5advancedlu\ch_09\net_geo.php on line 58

Our spies tell us the following information about the URL www.google.com:
IP Address: 209.85.229.147
Country:
City, State: ,

 

 

Any help with this would be greatly appreciated

Link to comment
Share on other sites

That would be great I have the same problems with PEAR AUTH as well, some of the PEAR packages work ok, but some produce a similar screen full of errors, I am also working my way through Your PHP6 and MySQL5 for dynamic web sites book as well, I have to say that I really like your style of writing,

Link to comment
Share on other sites

  • 1 month later...

So very sorry for the delay. I can normally get quick answers to people quickly and involved answers to people...

 

Thank you for the nice words on the work. I'm tacking a crack at this right now to see what I can figure out. Apologies again for the delay!

Link to comment
Share on other sites

So I installed Net_GeoIP along with the free GeoLite Country database (http://www.maxmind.com/app/geoip_country). Net_GeoIP works fine, but most of the functionality requires a paid database. So if this is something you want to pursue, it seems like you'll need to buy an IP Geolocation database and then you can use Net_GeoIP. The code for doing that is pretty easy and documented in the PEAR manual.

 

Apologies once more for the big delay!

Link to comment
Share on other sites

Hi thanks for your reponses,

 

I am pleased to know that it was not just me, as regards the GeoIp database I will look into that, but for the moment, I am trying to fill in certain gaps in my knowledge with PHP and MySQL, until I saw your book, I had never even considered PEAR, I had heard about it but thought that it was some old hangover from PHP 3 and had no real use.

 

I am glad that you have been able to open my eyes about the subject of PEAR but I also find that your books are written in such a way as to make building up my overall knowledge of all the related technologies easy, and fun to do.

 

So thanks again for your publications and keep up the great work.

 

Jon.

Link to comment
Share on other sites

Thanks for the nice words, Jon. Very much appreciated. I wrote about this in my newsletter some time back, but in some ways, the functionality of PEAR has been replaced by frameworks such as the Zend Framework. And the Zend Framework is also better maintained!

Link to comment
Share on other sites

Yes, I am still having a hard time with zend framework,

 

I have pretty much sorted out codeigniter and I am adapting my writing style to use OOP, but, just my observations, unless you are coding a pretty big project, i.e. 100's of pages a lot of the frameworks like zend/symfony seem to be a bit overkill, and overall tend to generate huge webpages and run more slowly, lightweight frameworks like codeigniter/doophp/rain framework tend to be more suited for smaller projects, I am still trying to decide about Yii, it seems to fit somewhere between codeigniter and zend but more toward zend.

 

As an example I am currently rewriting my main website using codeigniter, before I had written it old style PHP/MySQL mixture and had lots of pages and subsequently lots of entry points for would be hackers, with frameworks in general I like the single point of entry idea (everything delivered through a single index.php page) and of course the enhanced security that is included with most of them hence my interest in PEAR Auth.

 

Anyway sorry I seem to be wandering a bit off-topic.

 

So far I am about two-thirds of the way through a couple of your books and another one by a chap called Matt Doyle, the next thing on my list of things to learn will be the dreaded javascript, I have tried a number of times to understand exactly how that works but get confused by the myriad of javascript frameworks out there.

 

All the best

Jon

Link to comment
Share on other sites

Hey Jon,

 

To be clear, I don't actually like to use Zend for an entire Web site. I've tried, and didn't like it. But what I like about Zend is that you can use modules individually and they have some great ones. So I often use a Zend module or two in non-Zend sites, just like you could use PEAR. In fact, I've frequently used Zend modules in a Yii-based site.

 

You might be interested to know I'm writing a book on JavaScript right now.

Link to comment
Share on other sites

 Share

×
×
  • Create New...