Tag Archives: snippets - Page 2

How to hide Nginx version number in headers and errors pages

In default Nginx configuration, the server sends HTTP Header with the information of Nginx version number of the Server. The HTTP response header “Server” displays the version number of the server. This information can be used by hackers to try to exploit any vulnerabilities in the Nginx, specially if you are running an older version with known vulnerabilities.

Sample HTTP Response Header:

HTTP/1.1 200 OK
Server: nginx/1.2.6 (Ubuntu)
Date: Wed, 31 Jul 2013 19:47:33 GMT

Read more »

How to get size of BLOB in MySQL

Recently I wanted to get the size of the data stored in the BLOB field of a MySQL table. BLOB is a field which can be used to store variable amount of data. There is a simple MySQL String function, to find the size of BLOB data, OCTET_LENGTH. This function returns the length of BLOB in bytes. You can also use LENGTH function, because OCTET_LENGTH is synonym for LENGTH.

Sample usage:
Suppose in a table test_blob, there is a BLOB column (blob_content). We want to find the length of the BLOB field where id = 1.

SELECT OCTET_LENGTH(blob_content) FROM test_blob WHERE id = 1
I prefer to use OCTET_LENGTH, instead of LENGTH because the function name implies that I would get the result in terms of bytes and not characters.
Related Links:

How to apply a function to every array element in PHP

I often come across situations in which I need to apply some function to every element of an array in PHP. For example, to sanitize the user input, function like htmlentities can be used. We can easily use this function on a single variable or a single dimension array by simply applying the function or doing a foreach loop respectively. However, to do that on a multi-dimensional array is not very easy using foreach loop. In this article I will discuss the various methods we can use to apply the htmlentities function to a single variable and different types of arrays. The methods that I will discuss can be used to apply any default PHP function or any user defined function to every element of an array.

Read more »

How to remove WordPress version parameter from JS and CSS files

In my last post I mentioned how we can remove WordPress version number from the page source and RSS feeds. However, they are not the only places where we can identify the WordPress version number. Many CSS and JS files in the WordPress also have the WordPress version number appended to their source. In this post I will show how we can remove the version number from them too.

We can use one of the following 2 methods. Just added the code for one of the below methods in your theme’s functions.php file. The first method removes the “ver” parameter from all the enqueued CSS and JS files. The 2nd method removes the “ver” parameter only if its value matches the WordPress version number.
Read more »

How to remove WordPress version number

By default WordPress adds a meta tag which displays the WordPress version number that your WordPress site is running on. The version number is added just for tracking. This information can be useful to hacker to identify which version of WordPress you are running. If you are not running the latest version of WordPress the hackers can try to target the known vulnerabilities in that version to hack your site.

Note: This is just one way to identify the version. Also, even if this information is not available hackers might still try to hack it using other ways. So it is recommended that you always have the most up to date version of WordPress running.

In this post I will show you some wrong and right ways to remove this information.
Read more »