Remove WordPress Generator Tags: Powered by Visual Composer – drag and drop page builder for WordPress

Remove WordPress Generator Tags: Powered by Visual Composer – drag and drop page builder for WordPress

When using a WordPress theme that uses the ‘Visual Composer’,   a meta tag

  • Powered by Visual Composer – drag and drop page builder for WordPress

Is displayed on the output of each of your pages.

You can  use a tool like our WordPress Website Tool to see what generator meta tags are exposed by your WordPress installation

Since one of our initiatives here at Matraex, Inc while optimizing WordPress websites, is to remove the telltale signs of a WordPress installation,  we need a way that we can easily remove these tags.

We already have a plugin that we install into each of the WordPress websites that we manage which helps us to optimize each of them so we had a quick place we could add custom code to handle the removal.

This gives us a more reliable way to customize the output, without having to worry about the settings within different plugins.

We added the following code which removed the Visual Composer Generator Tag

add_action('init', 'optimize_fixwp_head', 100);
function optimize_fixwp_head() {
   remove_action('wp_head', array(visual_composer(), 'addMetaData')); 

Once you have added this,  you can do a very quick check to see that the meta tag has been removed using our WordPress Website Tool .  
The tool will also help you identify whether you have any other common WordPress exposure issues.


In researching the way to implement this thanks to :



Grep command to find all PHP shortcode entries

Grep command to find all PHP shortcode entries

As PHP files are moved from one server to the other,  occassionally we find a situateion where PHP was developed on a server that allowed shortcodes “<?”  which does not use the longer “<?php”  if this happens,  the PHP code does not execute and shows the code that would have executed,  on the output of the page.

When this happens I have found that using a simple command I can identify all of the places that use the short code

 grep -n '<?[^p=]' *.php

COMMANDDUMP – Upgrading from PHP 5.3 to 5.6 on Ubuntu 14.04

COMMANDDUMP – Upgrading from PHP 5.3 to 5.6 on Ubuntu 14.04

When upgrading from PHP version 5.3 to 5.6 there are several things to worry about.  On a shared system with multiple sites which do not make use of a common unit testing or library,  these tools and commands could be useful to find issues.  (this would also work from 5.4 or from 5.5 to 5.6)

COMMAND DUMP of things I ran.

Create a file call 5.4.php.searchterms

#echo import_request_variables >> upgrade.php.searchterms
#echo session_is_registered >> upgrade.php.searchterms
#echo session_register >> upgrade.php.searchterms
#echo session_unregister >> upgrade.php.searchterms
#echo define_syslog_variables >> upgrade.php.searchterms
#echo register_globals >> upgrade.php.searchterms
#echo sqlite >> upgrade.php.searchterms
#echo php_logo_guid >> upgrade.php.searchterms
#echo php_egg_logo_guid >> upgrade.php.searchterms
#echo php_real_logo_guid >> upgrade.php.searchterms
#echo zend_logo_guid >> upgrade.php.searchterms
#echo register_long_arrays >> upgrade.php.searchterms

#find -type f -name ‘*.php’ -exec grep -f upgrade.php.searchterms {} \; -ls

Check the version of your server

#lsb_release -a
#dpkg -l |grep php|grep apache
#php -v
#apache2ctl -vV

To upgrade from ubuntu 14.04 LTS you have to get php 5.6 from another repository as it is not includedin the default repos

apt-get -y update
apt-get install -y software-properties-common
add-apt-repository ppa:ondrej/php5-5.6 -y
apt-get -y update
apt-get -y install php5 php5-cli php5-common php5-curl php5-gd php5-imap php5-json php5-mysql php5-readline

You will be prompted when installing the latest version of PHP5 whether you want to keep the old or new version of PHP5.ini  I chosed to install the pakage maintainer’s version,   then I compare the two and update the new one with the differences.    The following command makes it easy to compare by removing all of the commented lines from the diff against the backed up file

cd /etc/php5/apache2
diff <(grep -v '^\s*;' php.ini|awk '$1 != ""') <(grep -v '^\s*;' php.ini.ucf-old|awk '$1 != ""')|more

I also updated the php.ini date.timezone setting to my area due to this post

date.timezone = America/Boise

/etc/init.d/apache2 reload

Preg_Match Visual Composer PHP Error

We started getting a preg_match Visual Composer PHP error that was: Warning: preg_match() expects parameter 2 to be string, array given in /wp-content/themes/bridge/vc_templates/vc_empty_space.php on line 12.


I was able to determine that when using the empty space feature for managing site contents in the design, if you saved “px” in the pixel value for the size of the empty space, WordPress results would throw this error. For example, if I saved 16px for the size, we would get this error message. However, if I went back in and just saved the value as 16 the system would work as expected.

This is only a slight fix, I have discovered that in a recent update to Visual Composer, the issue was resolved. So be sure you have updated to (at this time) v4.8

Here is a quick link to the Visual Composer plugin.



Find out which PHP packages are installed on ubuntu / debian

Find out which PHP packages are installed on ubuntu / debian

As we have moved or upgraded sites from one server to another,  sometimes we have needed to know which PHP5 dependencies were installed on one server servera,  so that we could make sure those same dependencies were met on another server serverb

To do this we can run a simply command line tool on server a

servera# echo `dpkg -l|awk '$1 ~ /ii/ && $2 ~ /php5/{print $2}'`
libapache2-mod-php5 php5 php5-cli php5-common php5-curl php5-gd php5-mcrypt php5-mysql php5-pgsql 

and then we copy the contents of the output and past it after the apt-get install command on serverb

serverb# apt-get install libapache2-mod-php5 php5 php5-cli php5-common php5-curl php5-gd php5-mcrypt php5-mysql php5-pgsql 

Dont forget to reload apache as some packages do not reload it automatically

serverb# /etc/init.d/apache2 reload

PHP Solution to http to https ajax call: No ‘Access-Control-Allow-Origin’ header is present on the requested resource

PHP Solution to http to https ajax call: No ‘Access-Control-Allow-Origin’ header is present on the requested resource

When submitting a form from an http:// site to an https:// via ajax,   you will run into the following error in the Chrome console

XMLHttpRequest cannot load No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '' is therefore not allowed access

This problem can come about if your current url is  and you are using an ajax POST or GET request to the site.

For example on you might have some JQuery such as



     ,data: 'username=bob&password=pass123'
     ,success: function(data){ $('div#login').html('You are logged in') }

To correct this, add the following PHP to the top of the loginform.php page.  Note the HTTP_HOST variable which should make it so that if you are simply trying to access the https:// site using the exact same domain name you will not have to change the code


    header("Access-Control-Allow-Origin: http://$_SERVER[HTTP_HOST]"); 


Browser, Tablet and Mobile Device Detection in PHP

Browser, Tablet and Mobile Device Detection in PHP

Many websites present different webpages, versions, navigation and styles depending the type of device.

We often run into this issue and have found a couple of tools to address it.

  • Browscap – – A feature built into PHP which compares the USER AGENT string against a HUGE (50MB+) ini file with regular expression matching.  The matching is comprehensive and very specific,  however the library of User Agents requires frequent updates in this world of every changing devices.   Each lookup can take several seconds,  and a high volume PHP site will likely need to come up with some sort of caching to handle the load caused by this tool.
  • Mobile Dectect – – A lightweight PHP Class which returns quickly.  While it has worked in many reguards,   the smaller size of the listing of User Agents leave me lacking in confidence that it will match all of the devices out there.

This sounds like an opportunity for me to build a comparison tool.   I will call it: browser-detect-compare and it will have the following features

  • When a user visits the page, their user agent is logged
  • Each of the tools in the comparison is queried to return the results
  • The site displays whether the results match between the tools for:
    • Is Mobile
    • Is Tablet
    • Browser Name
    • OS Name
    • OS Version
    • Browser Version
  • If the results do not match,  the user will be allowed to select which results are correct.
  • The site will then display statistics about how correct each of the tools are for each of the tracked metrics.

Please leave comments  of other features that will be use ful here.


Connecting to a database with PHP

Connecting to a database with PHP

Install these packages:

#apt-get install apache2
#apt-get install mysql
#apt-get install php
#apt-get install php5-mysql

Create a test user, password and database

At the sql server, Log into mysql:

#mysql -u root -p

Issue the following commands to create a user “test” and a password “password”:

CREATE USER ‘test’@’localhost’ IDENTIFIED BY ‘password’;
CREATE USER ‘test’@’%’ IDENTIFIED BY ‘password’;

GRANT ALL ON *.* TO ‘test’@’localhost’;
GRANT ALL ON *.* TO ‘test’@’%’;



Exit mysql:


Log back in as the user you just created, attaching to the new database:

mysql -u test -p instruments

Execute a


to see the status. Verify the user and database.

Test PHP Functionality:

Create a file named “something”.php and insert the following text:

<?php echo ‘hello world’.time();
/* <?php echo ‘mysqli_connect(); print_r(mysqli_query(‘select now()’)) ; ?> */

Place this file in the /var/www directory

Open a browser and point to that file:

http://<your server>”something”.php

You should see hello world and the date.

To test your connection to the database via PHP:

Create a file with the following text and name it “something”.php

Edit the line “$db = mysql_connect(“″,”test”,”password”);” to reflect your server & user.

$db = mysql_connect(“″,”test”,”password”);
if (!$db) {
die(“Database connection failed miserably: ” . mysql_error());

die(“Database Success!!!: ” . mysql_error());
$db_select = mysql_select_db(“instruments”,$db);
if (!$db_select) {
die(“Database selection also failed miserably: ” . mysql_error());
<title>Step 3</title>
$result = mysql_query(“SELECT * FROM mytable”, $db);
if (!$result) {
die(“Database query failed: ” . mysql_error());

Place this file in the /var/www directory

Open a browser and point to that file:

http://<your server>”something.php



Note that all text commands must be first on line and end with ‘;’
? (?) Synonym for `help’.
clear (c) Clear the current input statement.
connect (r) Reconnect to the server. Optional arguments are db and host.
delimiter (d) Set statement delimiter.
edit (e) Edit command with $EDITOR.
ego (G) Send command to mysql server, display result vertically.
exit (q) Exit mysql. Same as quit.
go (g) Send command to mysql server.
help (h) Display this help.
nopager (n) Disable pager, print to stdout.
notee (t) Don’t write into outfile.
pager (P) Set PAGER [to_pager]. Print the query results via PAGER.
print (p) Print current command.
prompt (R) Change your mysql prompt.
quit (q) Quit mysql.
rehash (#) Rebuild completion hash.
source (.) Execute an SQL script file. Takes a file name as an argument.
status (s) Get status information from the server.
system (!) Execute a system shell command.
tee (T) Set outfile [to_outfile]. Append everything into given outfile.
use (u) Use another database. Takes database name as argument.
charset (C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings (W) Show warnings after every statement.
nowarning (w) Don’t show warnings after every statement.

For server side help, type ‘help contents’

Matt Long

Connecting to a HANA Database using PHP from Ubuntu 14.04 LTS

Connecting to a HANA Database using PHP from Ubuntu 14.04 LTS

I need to setup a PHP Website to connect to a HANA.  The site is already installed with PHP and MySQL. Time permitting,  I will also document the process of converting the existing MySQL Database to HANA. The environment:

  • Hana OS: SUSE Linux Enterprise Server 11 SP3 x86_64 (64-bit)
  • Web Server: Ubuntu 14.04 LTS
  • PHP Version:5.5.9-1ubuntu4.5

First install the php odbc package

  1. sudo apt-get install php5-odbc

PHP ODBC Information

#php -i|grep odbc
ODBC_LIBS => -lodbc
odbc.allow_persistent => On => On
odbc.check_persistent => On => On
odbc.default_cursortype => Static cursor => Static cursor
odbc.default_db => no value => no value
odbc.default_pw => no value => no value
odbc.default_user => no value => no value
odbc.defaultbinmode => return as is => return as is
odbc.defaultlrl => return up to 4096 bytes => return up to 4096 bytes
odbc.max_links => Unlimited => Unlimited
odbc.max_persistent => Unlimited => Unlimited
PDO drivers => mysql, odbc

Install HANA Database Client

Before starting,   Since the Web server is on Amazon,  I just took a quick snapshot so I could rollback to a ‘Pre HANA Client State’ on the server if I needed to.

  1. Download the HANA using this link  SAP Hana Client  download the client,  you must be a member.  Sign up as a public user with all of your information,  you will be required to give them some information about your profession industry and company.    There are several screen and it takes quite a few before you get to the download.  BTW:If this link is broken,  please email me and let me know. -[ if this link does not work,  try it here }
  2. Extract the file into a temporary location and cd into the working directory
    1. cd /tmp
    2. tar -xvzf /home/michael/sap_hana_client.tgz
    3. cd sap_hana_linux64_client_rev80/
  3. Nexe ensure that the scripts that need to execute have execute privileges
    1. chmod +x hdbinst
    2. chmod +x hdbsetup
    3. chmod +x hdbuninst
    4. chmod +x instruntime/sdbrun
  4. Finally,  run the installation program
    1. sudo ./hdbinst -a client
    2. press <enter> to accept the default installation path: /usr/sap/hdbclient
    3. You will see  informaiotn like the following then you can take a look at the log file to see any other details of the installation.
      Checking installation...
      Preparing package 'Python Runtime'...
      Preparing package 'Product Manifest'...
      Preparing package 'SQLDBC'...
      Preparing package 'REPOTOOLS'...
      Preparing package 'Python DB API'...
      Preparing package 'ODBC'...
      Preparing package 'JDBC'...
      Preparing package 'HALM Client'...
      Preparing package 'Client Installer'...
      Installing SAP HANA Database Client to /usr/sap/hdbclient...
      Installing package 'Python Runtime'...
      Installing package 'Product Manifest'...
      Installing package 'SQLDBC'...
      Installing package 'REPOTOOLS'...
      Installing package 'Python DB API'...
      Installing package 'ODBC'...
      Installing package 'JDBC'...
      Installing package 'HALM Client'...
      Installing package 'Client Installer'...
      Installation done
      Log file written to '/var/tmp/hdb_client_2014-12-18_02.06.04/hdbinst_client.log'
    4. more /var/tmp/hdb_client_2014-12-18_02.06.04/hdbinst_client.log

I saw some reports online that you would have to isntall ‘libaio-dev’,  I did not have to,  but in case you do,  here is the command

  1.  sudo apt-get install libaio-dev

Now you can connect to the hana client

  1. /usr/sap/hdbclient/hdbsql

Ignoring unknown extended header keyword

This happened to me,  this is most likely because the tgz file was created on BSD.  to address this install bsd tar and replace the ‘tar’ command above with the bsdtar command below.

  1. apt-get install bsdtar
  2. bsdtar -xvzf /home/michael/sap_hana_client.tgz

Testing that the client can connect to a HANA server

To confirm that the client works, run the client and connect to the HANA server

  1. # /usr/sap/hdbclient/hdbsql
    Welcome to the SAP HANA Database interactive terminal
    Type: h for help with commands
          q to quit
  2. hdbsql=> c -n -u System -p mypass

I had to type a port,  most likly because the server was not installed on a default port.

Creating an ODBC Connection to HANA Server

First Install the unixodbc packages

  1. sudo apt-get install unixodbc unixodbc-dev odbcinst
  2. ls  /etc/odbc*
    /etc/odbc.ini /etc/odbcinst.ini

Open the /etc/odbc.ini file and type the following

Driver = /usr/sap/hdbclient/

Note that the blue matches the location you installed to,  you must make sure these match or you will receive a cryptic [ISQL]ERROR: Could not SQLConnect message.

Connect using your username and password

  1. isql hanadb username passwor
    | Connected! |
    | sql-statement |
    | help [tablename] |
    | quit |


Implementing the HANA  ODBC in PHP

As long as you have been able to connect via the ODBC methods above,  PHP should be a breeze.

Just place the following in your code.

  1. $link=odbc_connect(“hanadb”,”myusername”,”mypassword”, SQL_CUR_USE_ODBC);
  2. $result = odbc_exec($link,”select * from sys.m_tables “);
  3. while($arr=odbc_fetch_array($result)) print_r($arr);


A couple of gotchas:

  • Hana does not have the concept of ‘databases’,  they use schemas so the user you connect with must be setup to use the Schema you want by default.
    • Or you can prefix every table with your Schema name
    • Or you can set the default  context to the one you want before each connection
    • I accomplished this by adding an extra line under the odbc_connect();   odbc_exec($dblink, “set schema MYSSCHEMA”);

That’s it!   More posts to come on HANA.





Thanks to this post for help

PHP to reset all primary key sequences in your postgresql database

PHP to reset all primary key sequences in your postgresql database

Use the following php code t reset all of the primary key sequences with the max(id) currently in the db.

We use wrapper functions db_query (which returns an array from the db when a select statement is run)  and db_exec()  which runs an update or insert command against the db.

[code language=”php”]$sql = &quot;SELECT t.relname as related_table,
a.attname as related_column,
s.relname as sequence_name
FROM pg_class s
JOIN pg_depend d ON d.objid = s.oid
JOIN pg_class t ON d.objid = s.oid AND d.refobjid = t.oid
JOIN pg_attribute a ON (d.refobjid, d.refobjsubid) = (a.attrelid, a.attnum)
JOIN pg_namespace n ON n.oid = s.relnamespace
WHERE s.relkind = ‘S’
AND n.nspname = ‘public’&quot;;
$qry = db_query($sql);

foreach($qry as $row)
$outsql = &quot;select setval(‘$row[sequence_name]’,(select max($row[related_column]) from $row[related_table]))&quot;;


Fixed Hacked Site – PHP injection

Fixed Hacked Site – PHP injection

Today a customer called me about a PHP website that was popping up viruses all over the place.

I loaded up the site and there it was, the page was immediately redirected to a spyware / virus type site that tried to convince me to download their software to fix a problem. Since I knew better I carefully answered the browser prompts to make sure I closed out and left the page without opening anything malicious.
Then I went back to the page that had the problem and tried to load it again. But the problem was GONE!

After a bit more investigation I found that the people who wrote the virus dropped a cookie on my machine and made sure they allowed me back in the site. I am sure this trick helps them to keep the virus on a site for longer because the site administrators may not recognize it as an on going problem (or even a problem that their site caused).

In digging I found that each PHP page on the site had some PHP code added to the top of it.
something like

This was on a single line at the top of the file and even the administrator who had noticed the odd code at the top passed over it not thinking it was malicious.
However, the text inside the encoded string was VERY malicious. I decoded it and found several PHP functions and additional encoded strings.

I decided it wasnt worth figuring out what all they did with the code but instead decided to just clean it up. I assumed that the code probably helped replicate itself by checking that ALL other PHP pages on the site also had the same code in them. So if someone removed the code and then the code was run on another page it put itself back where you removed it.

Anyway, pretty sophisticated but it was easy for me to find the problem just opened and looked at the PHP file and saw code that shouldnt have been there.

A cool way that I found where the problem was before even opening the PHP file was to use HTTPWatch to see which exact files were downloaded from which site in the browser. I use the free version of the softwar and it has met all my needs so far. It is similar to firebug in FireFox.



Join our email list

and get your free whitepaper