File search and wildcards in PHP

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

Do you use Skype? Then Microsoft reads everything you write!

Posted by Stanislav Furman on May 21, 2013
Did you know that Microsoft reads everything you write in Skype?!

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

How to protect against SQL injection, and why SQL injection is dangerous

Posted by Stanislav Furman on May 14, 2013

I am quite sure that most of web developers know what the SQL injection is, and nowdays it seems that even junior developers know basics on how to protect web applications against this type of hacker attack. However, I often see web developers underestimate the level of potential threat. Some web developers think: "We are too small to be interesting for hackers", but they forget that security wholes in their applications can be used to attack other resources, systems and users.

In this post I am not going to show how to attack web applications using an SQL injection, but I'd like to show why SQL injection is dangerous and also how to protect against SQL injection.

Continue reading

jQuery 2.0 has released!

Posted by Stanislav Furman on April 24, 2013

In this release JQuery core developers threw out the support for Internet Explorer 6, 7 and 8 (Yay!). Thanks to this, the size of the library has decreased by 12% and now it's smaller and faster. It can be even smaller if you make your own build, disabling some of  built-in default modules (there is 12 of them).

Those who need old IE support should remain on the branch 1.x, which will continue supporting old IE versions.

Continue reading

How to trim array elements in PHP in one shot

Posted by Stanislav Furman on April 18, 2013

If you are looking for a method to trim leading and trailing white spaces in all elements of a PHP array, you could use the following code:

<?php
// custom function to trim value
function _trim(&$value) 
{
    $value = trim($value);    
}

$data = array('  a  ',' b',' c   d ');
array_walk($data,"_trim");

var_dump($data);

/*
Output:
array (size=3)
  0 => string 'a' (length=1)
  1 => string 'b' (length=1)
  2 => string 'c   d' (length=5)

*/

This works, but might look a little long. If you want a shorter solution, here it is:

Continue reading

How to get most accurate visitor's IP address in PHP

Posted by Stanislav Furman on April 15, 2013

Web developers often need to get visitor's IP address to use it in web applications. This can be used in internal traffic analytics tools, or as a part of security measures.

Most common and standard method of getting visitor's IP address is getting the value "REMOTE_ADDR" from the global PHP array $_SERVER:


<?php
$visitor_ip = $_SERVER['REMOTE_ADDR'];

However, standard PHP $_SERVER['REMOTE_ADDR'] value not necessarily contains the originating visitor's IP address because, for example, visitor can use a proxy server to access your web site. Using PHP we could try to detect user's IP address even if he uses proxy, but keep in mind that there is no guarantee that IP address that you get is 100% accurate (e.g. proxy can be anonymous).

Continue reading

Why start and run your own blog?

Posted by Stanislav Furman on April 1, 2013

There is a lot of different blogs exist in the Internet. However, every day people set up tons of new blogs, and at the same time huge number of blogs die every day. So, why would people create and run their own blogs?

Continue reading

Reading file list from a mapped Windows network drive

Posted by Stanislav Furman on March 25, 2013

Last week I ran into a situation when I had to read directory file list from a mapped Windows network drive. At your very first look it may seem pretty simple. It is! However, there is a little trick - Windows may require your network/domain credentials, and then standard PHP functions such as opendir() won't be able to access the directory. Fortunately, the solution is pretty simple:

Continue reading

MySQL. How to insert a row or update if exists in MySQL.

Posted by Stanislav Furman on February 25, 2013
Insert a row into DB, or update row on duplicated key in MySQL.