Getting client’s real IP behind reverse proxy

The problem: when try to retrieve client’s ip in Laravel with $request->ip(); it always return the reverse proxy IP address.

In order to retrieve the client’s real IP the frontend server has to forward the client’s IP into the backend server.

NGINX front end configuration:

location /api {
    proxy_pass; // your api backend server address
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Real-Port $remote_port;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Port  $server_port;
    proxy_set_header HTTP_X_FORWARDED_FOR $remote_addr;
    proxy_redirect default;

NGINX back end configuration

server {
    # ...
    real_ip_header X-Forwarded-For;

Apache back end configuration

<VirtualHost _default_:443>
# ...
RemoteIPHeader X-Forwarded-For

Once the configuration is in place, client’s real ip should be forwarded to the backend server.

Laravel get client’s IP

echo request()->ip();
Posted in Development | Tagged , , , | Leave a comment

Macbook Pro 2011 defective GPU

GPU recall back in 2015

GPU recall were done back in 2015, and now it failed again.

This is how I fixed the 2011 Macbook pro with defective AMD GPU, boot into command line and remove all those AMD driver, this will force the OS to use the Integrated GPU.

Boot into command line mode CMD+S and entering these commands:

1) fsck -fy (to check a disk)
2) mount -uw / (mount a root filesystem with read/write permissions)
3) sudo mkdir /AMD_Kexts/ (make a directory to store the AMD drivers in case you’ll need them in future)
4) sudo mv /System/Library/Extensions/AMD*.* /AMD_Kexts/ (move the AMD drivers)
5) sudo rm -rf /System/Library/Caches/ (remove the AMD drivers cache)
6) sudo mkdir /System/Library/Caches/ (just in case OS X will be dumb and will not recreate this directory, I am creating it for OS X)
7) sudo touch /System/Library/Extensions/ (to update the timestamps so that new driver caches – without AMD drivers – will be definitely rebuilt)
8) sudo umount / (umount a partition to guarantee that your changes are flushed to it)
9) sudo reboot

Posted in Development | Tagged , | Leave a comment

Laravel using captcha validation

install captcha dependence with composer

composer require mews/captcha

add the class interface into ‘providers’ section in config/app.php


define alias into the ‘alias’ section

'Captcha' => Mews\Captcha\Facades\Captcha::class,

execute command to create configuration file

php artisan vendor:publish

edit the config file accordingly in config/captcha.php

'default'   => [
    'length'    => 4,   // length of the captcha
    'width'     => 90, // width of the image
    'height'    => 32,  // height of the image
    'quality'   => 90,

the code to show the captcha in the form

<img src="{{captcha_src()}}" style="cursor: pointer" onclick="this.src='{{captcha_src()}}'+Math.random()">
Posted in Development | Tagged , , | Leave a comment

PHP convert character encoding to UTF-8

a simply function that detect character code and covert to UTF-8

function convertUTF8($data) {
  if(!empty($data)) {    
    $encodeType = mb_detect_encoding($data , array('UTF-8','GBK','LATIN1','BIG5'));   
    if( $encodeType != 'UTF-8'){   
      $data = mb_convert_encoding($data ,'utf-8' , $encodeType);   
  return $data;    
Posted in Development | Tagged , , | Leave a comment

Excel mask out card number

The following code will mask out the card number


Posted in Development | Tagged , | Leave a comment