Posts Tagged with "tricks"
File search and wildcards in PHP
Posted by Stanislav Furman on June 7, 2013How to trim array elements in PHP in one shot
Posted by Stanislav Furman on April 17, 2013How to get most accurate visitor's IP address in PHP
Posted by Stanislav Furman on April 15, 2013Web 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 readingReading file list from a mapped Windows network drive
Posted by Stanislav Furman on March 25, 2013Last 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