Can't get MaxMind Reader to work - php

According to their PHP Packagist repository page
https://packagist.org/packages/maxmind-db/reader
the following code is all I need to get the reader to work. PHP doesn't seem to like the use MaxMind\Db\Reader;line. Any clue on how to fix this so it uses the reader.
require_once 'vendor/autoload.php';
use MaxMind\Db\Reader;
$reader = new Reader('GeoIP2-City.mmdb');
print_r($reader->get($_SERVER['REMOTE_ADDR']));
$reader->close()

Okay the solution I figured out is that anything that uses the keyword [use] need to be first in the PHP document; e.g. API.

Related

GeoLite2: Reader Class not recognized

I'm using PHP to retrieve the city of an IP using the GeoLite2 Free Downloadable Database.
The code I'm using is the following one:
function getGeoLocationFromIp()
{
include_once('Db/Reader.php');
include_once('Db/Reader/Decoder.php');
include_once('Db/Reader/InvalidDatabaseException.php');
include_once('Db/Reader/Metadata.php');
include_once('Db/Reader/Util.php');
//use MaxMind\Db\Reader;
$reader = new Reader('/sys/class/GeoLite2-City.mmdb');
$ipData = $reader->get('xx.xx.xx.xx');
return $ipData;
}
The Db folder is in the following path: "www/Admin%20Panel/Db" and so the city database "www/Admin%20Panel/sys/class/GeoLite2-City.mmdb".
As you can see I commented use MaxMind\Db\Reader; because it crashes my web page.
I always had a problem with Classes and for this reason I never used them but now I have to and, as feared, they don't work.
I'm working directly online so I'm not even able to see the error log.. :(
Any idea on how I can make that Class work?
Thank you all :)

Connecting to the Quickbooks Online SDK from PHP, how do I add a Blue Dot menu?

I have a working PHP app that connects to Quickbooks online, loosely based on code from Pearce (thank you!). I'm using the Intuit PHPv3 SDK (version 2.0.4).
My setup code looks like:
<script type='text/javascript' src='https://appcenter.intuit.com/Content/IA/intuit.ipp.anywhere.js'></script>
<ipp:connectToIntuit></ipp:connectToIntuit>
and then, in Javascript:
intuit.ipp.anywhere.setup({
grantUrl: 'http://mywebsite.com/qbo/oauth'
});
This works fine, but I would like to add a Blue Dot Menu, which I assume gives the ability to disconnect the session and do other things. To do this, I know that the Javascript should really be saying:
intuit.ipp.anywhere.setup({
grantUrl: 'http://mywebsite.com/qbo/oauth',
menuProxy: 'http://mywebsite.com/qbo/blue-dot-menu
});
Trouble is, I have no idea what to put in the implementation code for the blue-dot-menu handler, and I've now spent quite a long time trying to figure this out from Intuit's documentation without success.
Any ideas appreciated!
The implementation of the Blue Dot menu is actually pretty simple -
Make a HTTP GET request to:
https://appcenter.intuit.com/api/v1/account/appmenu
That's OAuth authenticated. Print out the contents of what you get back to the page. Boom, done.
If you want an actual working example, use the open-source DevKit on GitHub - examples are here:
https://github.com/consolibyte/quickbooks-php
Specifically these examples:
https://github.com/consolibyte/quickbooks-php/tree/master/docs/partner_platform/example_app_ipp_v3
Which have a working example of the Blue Dot menu all ready to go for you, wrapped up in a nice OOP wrapper:
https://github.com/consolibyte/quickbooks-php/blob/master/docs/partner_platform/example_app_ipp_v3/menu.php
It's this simple:
<?php
require_once dirname(__FILE__) . '/config.php';
// Display the menu
die($IntuitAnywhere->widgetMenu($the_username, $the_tenant));
You can have a look at the following JAVA implementation.
https://github.com/IntuitDeveloperRelations/IPP_Sample_Code/blob/master/QuickbooksAPI/Java/Spring%20Application/QuickBooksAPI/src/main/java/com/intuit/controller/support/BluedotController.java
You need to make the following call in the PHP way(using the OAuth and Http libs).
final IAPlatformClient pClient = new IAPlatformClient();
final StringBuffer stringBuffer = new StringBuffer();
final List<String> menuList = pClient.getAppMenu(WebUtils.OAUTH_CONSUMER_KEY, WebUtils.OAUTH_CONSUMER_SECRET, accesstoken, accessstokensecret);
Other things are quite straight forward.
Hope it will be helpful.
Thanks

How to use Httpful PHP Library

I'm trying to learn REST, and thought it might be good to start with a PHP REST client such as Httpful. I just can't seem to get it to work. I downloaded the httpful.phar file and placed it in my working directory. Then created a simple php file with the following contents from an example on the their site:
<?php
// Point to where you downloaded the phar
include('httpful.phar');
$uri = "https://www.googleapis.com/freebase/v1/mqlread?query=%7B%22type%22:%22/music/artist%22%2C%22name%22:%22The%20Dead%20Weather%22%2C%22album%22:%5B%5D%7D";
$response = Request::get($uri)->send();
echo 'The Dead Weather has ' . count($response->body->result->album) . " albums.\n";
?>
I've tried multiple examples on the site, but only get a blank page when I load it in my browser.
Thanks for any help you can give!
This library uses Namespaces. Either use a complete classname or use the class
With a complete Classname:
\Httpful\Request::get($uri)->send();
With a use:
use Httpful\Request;
Request::get($uri)->send();
The sample code sadly is very incomplete on the website, but you can get the hint from sample below topic "INSTALL OPTION 1: PHAR" or from the actual source code inside the phar.
http://phphttpclient.com/

MemcachePool not found

I am trying to use MemcachePool in my code, it reports the following error in PhP:
PHP Fatal error: Class 'MemcachePool' not found in test.php
Here is the code snippet:
$this->mMemcached = new MemcachePool();
$this->mMemcached->addServer(...)
i never heard of MemcachePool - maybe you just wanted to use Memcache (thats where addServer() can be found)? in that case, just change your code to:
$this->mMemcached = new Memcache();
$this->mMemcached->addServer(...);
if this isn't what you're looking for, MemcachePool has to be a third party extension that hasn't been installed or a custom (wrapper)-class wich you forgot to include.

phpgrid using codeigniter

I'm working on a web application using codeigniter and i want to use php grid
in displaying information but i dont know how to do it with codeigniter! Is there anyone has worked with php grid using codeignitier? Help please!! I'm would have opted for flexigrid
but it doesn't offer so much functionality such as exporting to various document format(excel, word, e.t.c).
Thanx in advance!
I'm not familiar with php grid, but usually you can just throw a class file in application/libraries and then load it like this:
$this->load->library('phpgrid');
// and use it like this
$this->phpgrid->phpgrid_method();
You can use the following code to load php datagrid or any 3rd party PHP libraries.
$this->load->library('phpgrid');
Another approach in CodeIgniter is to directly include third party libraries without calling load library.
require_once(APPPATH. 'libraries/phpGrid_Lite/conf.php');
$data['phpgrid'] = new C_DataGrid("SELECT * FROM Orders", "orderNumber", "Orders"); //$this->ci_phpgrid->example_method(3);
APPPATH is explained in this SO discussion.

Categories