How to prevent SQL injection?

Important is that any parameter in a query needs to be parameterized. It doesn’t matter is your query is select, insert, update or delete kind of query, since every query can be used for injection. Let’s say that you want to have basic SELECT query, like: SELECT `column1` FROM `table1` WHERE `column2` = 11; You…

How to get free space on server?

If you want to get info about free space on server, or in particular directory, execute next code in your browser – it will give you info about free space on server’s directory defined in variable $dir: $dir = ‘/var/www/htdocs/’; $space = round(disk_free_space($dir) / 1024 / 1024 / 1024); echo (“Free space: ” . $space…

How to get file extension (without parsing file name)

Get file extension without use of explode function of preg functions You can use pathinfo function – it will return an array with elements like: dirname basename extension filename Reading those values you will get proper values. <?php $path_parts = pathinfo(‘/var/www/htdocs/index.php’); echo $path_parts[‘dirname’]; echo $path_parts[‘basename’]; echo $path_parts[‘filename’]; // since PHP 5.2.0 echo $path_parts[‘extension’]; ?>

How to check if function exists?

Or – how to avoid re-declaring functions? Function redeclaration often occurs if you work with different versions of PHP, ie. on development and on production server. In that case we usually use PHP function function_exists. In next example we will check if function money_format is defined or not. if (!function_exists(‘money_format’)) {   function money_format() {…