Posts Tagged with "how-tos"

Detect an Ajax request in PHP

Posted by Stanislav Furman on August 24, 2017

If you would like to use same PHP code to handle both AJAX and non-AJAX requests, here is a quick and simple trick that you can use to check if the incoming request is AJAX. For our trick we will use a HTTP header called HTTP_X_REQUESTED_WITH. It is supported by all modern browsers that support AJAX. Therefore, it should work in 99% of cases.

Continue reading

Delete all Docker containers and images

Posted by Stanislav Furman on September 9, 2016

First time I heard about Docker was beginning of 2016. Finally, I got a chance to try Docker in "wild nature".

One of the most common things you might need from time to time is to stop or remove all your Docker images in one shot. Here are some simple and useful commands to stop or remove all of Docker containers.

Before deleting Docker containers we need stop them:


$ docker stop $(docker ps -a -q)

Now, when our Docker containers are not running, we can delete them:


$ docker rm $(docker ps -a -q)

Also there is a nice untility to clean your Docker images, volumes and networks. It's called Docker Clean.


How to use optional parameters in URI path in Yii framework

Posted by Stanislav Furman on July 10, 2014
Read about how to use optional parameters in URL manager in Yii framework

How to update fields from another table in MySQL

Posted by Stanislav Furman on May 28, 2014
Read how to update a bunch of fields from another table in MySQL

Unix shell commands to detect a DDoS attack and its source

Posted by Stanislav Furman on April 25, 2014

5 unix shell commands to detect a DDoS attack

Hello Coders!

In this article I'd like to show you a few handy Unix shell commands that would help you to detect if your server is (was) under DDoS/DoS attack. However, keep in mind, that protection from DDoS attacks is quite complex and if you are dealing with a massive DDoS attack, you would need to contact your IPS or Hosting Provider (i.e. 1&1) for assistance. 

So. What do we work with? We can do some analysis based on your Apache access log data. Assuming you have a standard Apache access log, and you are running your website on Unix. Let's now get the total number of requests per day:

## Get number of requests per day:


awk '{print $4}' access.log | cut -d: -f1 | uniq -c

This will display you a list the total number of HTTP requests per day. See if you have any unusual increses comparing to other days. Now see the total number of requests per hour for a specific date (April 25th in this example):

Continue reading

Redis: How to delete keys matching a pattern

Posted by Stanislav Furman on April 10, 2014

Sometimes you might want to purge a set of similar Redis keys in one shot. So far, standard Redis "DEL" command does not allow to remove keys using patterns. However, there is a trick to do this action. Execute the following command in bash:


redis-cli -h [host] -p [port] KEYS "prefix:*" | xargs redis-cli DEL

Seems clear? Wait a minute! What if you use multiple databases (keyspaces) and need to remove keys from a database different from default (0) one? No problem there! Here is the solution:

Continue reading

Backward version compatibility in PHP web application

Posted by Stanislav Furman on February 17, 2014

If you develop a PHP web application which may be used on a web server with older PHP version, you can run into a situation when some of the PHP functions in your application won't work at all, or won't work as expected.

In fact, you can handle those situations if you want to. However, it can make you application code not as nice as you want and a little heavier.

Continue reading

How to recognize a good programmer

Posted by Stanislav Furman on September 30, 2013
How to find a good programmer: most important indicators of a good professional

File search and wildcards in PHP

Posted by Stanislav Furman on June 7, 2013
How to search files in PHP using wildcards and patterns

Concatenating NULL and blank fields in MySQL

Posted by Stanislav Furman on May 17, 2013
How to concatenate empty and null fields in MySQL database