GeoIP alternative to get IP location – Google App Engine PHP Recipes

Today’s recipes is all about to get very basic information about your visitor’s IP address location. Unfortunately, in Google App Engine, PHP GeoIP extension is not enabled in their standard environment. So sometimes, it’s essential for application developer to get the visitor’s IP address location.

Here, you can easily get user’s IP address location with 3 information easily and by default from Google App Engine. In GAE, if you will discover that Google app engine itself added few extra _X_headers in $_SERVER super-global variable. I am dumping the $_SERVER variable here.

//Output of $_SERVER

    'AUTH_DOMAIN' => '',
    'CURRENT_MODULE_ID' => 'default',
    'CURRENT_VERSION_ID' => '20170319t185047.399949465273621812',
    'DOCUMENT_ROOT' => '/base/data/home/apps/xxxxxxxxxxxxxx/20170319t185047.399949465273621812',
    'HTTPS' => 'on',
    'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*\/*;q=0.8',
    'HTTP_ACCEPT_LANGUAGE' => 'en-US,en;q=0.8,bn;q=0.6,ms;q=0.4,pt;q=0.2',
    'HTTP_HOST' => '',
    'HTTP_USER_AGENT' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.110 Safari/537.36',
    'HTTP_X_APPENGINE_CITY' => 'dhaka',
    'HTTP_X_APPENGINE_CITYLATLONG' => '23.709921,90.407143',
    'HTTP_X_CLOUD_TRACE_CONTEXT' => 'xxxxxxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxxx;o=x',
    'INSTANCE_ID' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    'PATH_TRANSLATED' => '/base/data/home/apps/xxxxxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxxxxx/index.php',
    'PHP_INI_SCAN_DIR' => '/base/data/home/apps/xxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxxxxx/',
    'PHP_SELF' => '/index.php',
    'REMOTE_ADDR' => '',
    'REQUEST_LOG_ID' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    'REQUEST_URI' => '/',
    'SCRIPT_FILENAME' => '/base/data/home/apps/xxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/index.php',
    'SCRIPT_NAME' => '/index.php',
    'SERVER_NAME' => '',
    'SERVER_PROTOCOL' => 'HTTP/1.1',
    'SERVER_SOFTWARE' => 'Google App Engine/1.9.48',
    'USER_IS_ADMIN' => '0',
    'REQUEST_TIME_FLOAT' => 148992.7,
    'REQUEST_TIME' => 14899,
    'argv' =>
    'argc' => 0,

//Get the visitor's IP details
$visitorIp = [
    'ip' => $_SERVER['REMOTE_ADDR'],


And from that, we can easily get the visitor’s City, City-level lat long, country and region that primary will help you to get visitor’s location.

Slim PHP Framework PhpStorm IDE autocompletion Solution

I am a big fan of PHP Slim Framework. But sometimes, I realized that when I work with large and complex libraries with Slim as dependency. It just kills my productivity, it kills my valuable time too. It’s all because of I can’t remember all the method names, properties of my dependent class or libraries. And with Pimple dependencies Slim Framework don’t have any way to bypass referencing of my third party libraries which I add through it’s container as dependency. So I decided to figure out a solution for me.

First, I just installed and configured slim framework and here is my scripts.

require "../vendor/autoload.php";
$app = new \Slim\App();
$container = $app->getContainer();

 * @return \ShahariaAzam\Classes\HintsClass
$container['hints'] = function () {
 return new \ShahariaAzam\Classes\HintsClass();

$app->get('/foo', function (\Slim\Http\Request $request, \Slim\Http\Response $response) {
 /** @var Dummy $this */
 $response->write("Hello World");

$app->get('/another-foo', function (\Slim\Http\Request $request, \Slim\Http\Response $response) {
 /** @var Dummy $this */


And I created a class HintsClass. Now the main trick is, I created a dummy _ide_autocomplete.php file in the project root and defined all the containers key as public property. Like this.

namespace ShahariaAzam\Classes;

 * Class HintsClass
 * @package ShahariaAzam\Classes
class HintsClass
     * @var int
    public $test = 1;

     * @return bool
    public function testMethod()
        return true;

     * @return string
    public function printHelloWorld()
        return "HelloWorld";


Now our goal is from inside route, our PHPStorm IDE will show the autocomplete and hinting for code completion when we will access this class with $this->hints->[ctrl+space to see autocompletion]. And in our _ide_autocomplete.php file we wrote the following codes. FYI, this _ide_autocomplete.php will never execute. It just used for giving IDE as a referential hinting for all the properties .


class Dummy
     * @var \ShahariaAzam\Classes\HintsClass
    public $hints;


You will see in this Dummy class file according to our slim containers[‘hints’], I just mentioned the same return reference here. And see my main index.php, in every route I just gave IDE hints about the $this context with

/** @var Dummy $this */

And after that from route context IDE will show the autocompletion of our dependencies like $this->hints[ctrl+space to see suggestions].

You can see my whole scripts are in GitHub And see this work in YouTube, .Please let me know if any issue found, write me in comments. Thank you.

Connect Google Cloud SQL from Local Machine using Unix Socket

You need to install Google Cloud SDK and check if you have gcloud command available in terminal. After installing gcloud you need to configure gcloud sdk by running gcloud init command.

I am assuming, you have configured your Google Cloud SQL instance for your project. If yes, then continue, otherwise you need to read “Google Cloud SQL Quickstarter Guide“.

Now Download cloud_sql_proxy.linux.amd64 package in your local machine with

"sudo wget"

this command.

Rename by mv cloud_sql_proxy.linux.amd64 cloud_sql_proxy
and give execution permission by chmod +x cloud_sql_proxy

Create application default credentials using “gcloud auth application-default login” command

Create a directory sudo mkdir -p /cloudsql for Google Cloud SQL proxy unix socket and make that directory writable sudo chmod 777 /cloudsql

start sql socket proxy by ./cloud_sql_proxy -dir=/cloudsql &

At last,
Now you can have working mysql DSN “mysql:unix_socket=/cloudsql/INSTANCE_CONNECTION_NAME” which you can use in your application and your application will work with Google Cloud SQL instance directly from local machine.

Please ask me anything about this post in comment below. I will be glad to assist you happily.


Get ThemeForest theme information and stats with simple PHP script

Now a days, lots of professionals are selling their creative works on ThemeForest. I just created the following simple (very simple) PHP script that works with HTML DOM and XPATH will do a very interesting job to show the ThemeForest theme information and statistics.

Just run this script on your PHP environment and you will get the following information of any specific ThemeForest theme.

    [sellCount] => 2
    [price] => $16
    [created] => 2016-10-13
    [lastUpdated] => 2016-10-13
    [highResolution] => No
    [compatibleBrowsers] => IE10,IE11,Firefox,Safari,Opera,Chrome,Edge
    [filesIncluded] => HTMLFiles,CSSFiles,JSFiles
    [columns] => 1
    [documentation] => Unrated
    [layout] => Responsive
    [totalComment] => 8


WHMCS PHP API – Integrate billing system with your application

WHMCS is a popular billing system specially for domain+hosting business. It provides mostly billing solutions. You can download WHMCS from download page. As a billing system, if you have several tools, utilities and services that require connection between your application and WHMCS then you badly need API to accomplish that interconnection.

WHMCS has a very basic API documentation (it’s enough though) without any specific programming library. You can use the following wrapper class to interact with your WHMCS system from your PHP application. This is very simple and doesn’t require further explanation in depth. See the following script. If you have any better idea or suggestions, don’t forget to write me in the comment area.