PHP Tips and Tricks
A roundup of ten PHP tips and tricks from DevChunks, covering dates, redirects, error reporting, the GD library, sending email and more.
A roundup of ten PHP tips and tricks from DevChunks, covering dates, redirects, error reporting, the GD library, sending email and more.
More ways to hide PHP usage from visitors: extension-less files via ForceType, MultiViews, and turning off expose_php in php.ini or per file.
How to hide that your site runs on PHP by giving PHP files a different extension and configuring it with an AddType line in .htaccess.
How to send email from PHP with the mail() function, validate addresses with FILTER_VALIDATE_EMAIL, and when to switch to the PEAR Mail package.
Two simple ways to get the Apache and PHP version info running your site, using phpinfo() or SERVER_SIGNATURE, plus how to extract just the versions.
How to create images on the fly in PHP with the GD library, using imagecopyresized and imagecopyresampled to build and save dynamic thumbnails.
How to control PHP error reporting levels with the error_reporting() function and constants like E_ALL, E_WARNING, E_NOTICE and E_PARSE.
How the PHP ignore_user_abort() function controls whether a remote client can abort a running script, with a full working example.
How to format prices for different currencies in PHP with number_format(), covering English and French notation and what each argument does.
How to redirect visitors with the PHP header() function, why output before it breaks the redirect, and when to send a 301 versus a 302 status code.
How to display the current date and time with the PHP date() and time() functions, plus an example using the PEAR Date class for time zones.
How to use an UPDATE query to change existing data in your MySQL tables, with the syntax explained.