Customizing Google Calendar Colors

<iframe src="/gcalendar-wrapper.php?src=[google calendar embed url here]" style="border: 0" width="100%" height="600" frameborder="0" scrolling="no"></iframe>

Go to and get the embed code

Hover to your calendar and click the arrow down symbol. Then click Calendar Settings.
You can find the embed code in Calendar Details

Download the file here

Parsing WordPress RSS Feed

Tested in content types

$url = '';
$feed1_xml = simplexml_load_file($url) or die("feed not loading");

To get the first post title
echo $feed1_xml->channel->item[0]->title;

To get the first post published date
echo $feed1_xml->channel->item[0]->pubDate

Returned date is in this format Wed, 20 Apr 2016 04:22:10 +0000
You can also convert it to ‘Y/m/d’

New Custom Post Type is not working

-rw-r--r-- 1 user members 842 3月 8 18:21 single-about.php
-rw-r--r-- 1 user members 842 3月 8 18:36 single-course.php

I already have an existing custom post type “about”. It’s loaded using single-about.php
I added new custom post type “course” and copied single-about.php content to single-course.php but the new post under “course” custom post type cannot be viewed.
And there’s also no sign that single-course.php is used.

The solution was to flush rewrite, you can do this by going to Settings > Permalinks and just hit Save Changes and everything works as expected after that.

Could Not Find Driver in Ubuntu CLI

Note, the PHP version of Apache and Terminal could be different.
Web phpinfo() shows

Loaded Configuration File /etc/php5/apache2/php.ini
PDO drivers | mysql, sqlite

Checking on the terminal

$ php -i |grep php\.ini
Configuration File (php.ini) Path => /etc/php/5.6/cli
Loaded Configuration File => /etc/php/5.6/cli/php.ini

Checking for drivers
$ php -i|grep PDO
PDO support => enabled
PDO drivers =>

As we see we have no drivers

Ubuntu 14.04.3 LTS
sudo apt-get update
sudo apt-get install php5.6-fpm php5.6-mysql
$ php -i|grep PDO
PDO support => enabled
PDO drivers => mysql
PDO Driver for MySQL => enabled

Installing PHP 7 with Ubuntu

To fix “Could Not Find Driver” error
Ubuntu 16.04.1 LTS
sudo apt-get update;
sudo apt-get install php7.0-fpm php7.0-mysql

Protecting WordPress Login

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

# Stop Apache from serving .ht* files
<Files ~ "^\.ht">
Order allow,deny
Deny from all

# Protect wp-login
<Files wp-login.php>
AuthUserFile ~/.htpasswd
AuthName "Private access"
AuthType Basic
AuthUserFile /absolute-path-to-htpsswd/.htpasswd
Require valid-user

Integrate Laravel and Chat Server using WebSocket

Create a file chat-server.php
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use App\Http\Chat;
require 'vendor/autoload.php';
//load laravel framework
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
$server = IoServer::factory(
new HttpServer(
new WsServer(
new Chat()
'' //allow none-localhost ip

App\Http\Chat.php is a class that implements Ratchet\MessageComponentInterface. Detailed implementation is found here

To run, open commandline and type $ php chat-server.php If you update the file and related to it make sure to restart the chat server using Ctrl+C then running the command again.

If you encounter “Could not find driver” while using chat-server.php that means there is no enabled mysql driver in php terminal. You can find solutions here

DateTime() is better than strtotime()

I’m using Windows 64 bit and PHP 5.6

strtotime() can’t go beyond 2038 year

$number_of_years = 2;
$start_date = '2037-12-31';
$end_date = strtotime('+' . $number_of_years . ' year', strtotime($start_date));
$end_date = strtotime('-1 day', $end_date);
echo 'strtotime() Result: '.date('Y-m-d', $end_date);

echo "<br/>";

$d = new DateTime($start_date);
$d->modify("+".$number_of_years." year");
$d->modify("-1 day");
echo 'DateTime() Result: '.$d->format('Y-m-d');


strtotime() Result: 1969-12-31
DateTime() Result: 2039-12-30

Usage of DateTime() is also easier.