background preloader

PHP

Facebook Twitter

Advanced PHP Error Handling via htaccess. In my previous article on logging PHP errors, How to Enable PHP Error Logging via htaccess, we observed three fundamental aspects of preventing, preserving, and protecting your site’s PHP errors: Prevent public display of PHP errors via htaccess # supress php errors php_flag display_startup_errors off php_flag display_errors off php_flag html_errors off php_value docref_root 0 php_value docref_ext 0 Preserve (log) your site’s PHP errors via htaccess # enable PHP error logging php_flag log_errors on php_value error_log /home/path/public_html/domain/PHP_errors.log Protect your site’s PHP error log via htaccess # prevent access to PHP error log <Files PHP_errors.log> Order allow,deny Deny from all Satisfy All </Files> Now, in this article, we will explore these operations 2 in greater depth, provide additional functionality, and examine various implications.

Advanced PHP Error Handling via htaccess

Controlling the level of PHP error reporting # general directive for setting php error level php_value error_reporting integer Useful Links. Ajax upload with XMLHttpRequest level 2 and the File API. I’ve put together a micro Ajax library for the XMLHttpRequest level 2 spec. You can go check it out on Github or read the related article XMLHttpRequest Level 2 Ajax library, xhr2-lib Ajax applications are wide spread these days and one thing that has proven a pain in the arse is uploading files. I’m sure most people will have fired off a fake asynchronous upload to a hidden iframe or used a sneaky swf to handle it but now with the development of the level 2 specification for the XMLHttpRequest object some of those woes may soon (if you are ok about not supporting IE) be a thing of the past.

The FileReader API and the DataTransfer object One of the coolest things I’ve messed about with so far in HTML5 is the FileReader and File APIs and their ability to read in files from the users computer. XMLHttpRequest object send() with File In the level 2 specification the send method can accept a File object argument which allows us to stream binary chunked data to the server asynchronously. Summary. Caching API responses with PHP. Most websites have some kind of widget that fetches data from an external RESTful API provided by services such as Twitter, Flickr and Facebook to name just a few. These APIs often limit the amount of hits any one Domain/IP can make and if you go over your rate limit then pow, no data for you and an empty widget. This PHP class gives you a mechanism to cache your API responses locally and only update them on a set time interval so you always stay within the rate limits for each API call you make from your site.

API_cache.php The class accepts a URI for your API call, a filename to write to (if this is not in the same directory as the class you will need to make sure that directory exists), and a time period for how long you wish to cache the response for. Each time the cache contents are requested the object checks to see if the file is out of date before updating it and returning the files contents. Using the API_cache class effectively. Special effects using imagefilter() Bool imagefilter ( resource image, int filter_type [, int parameter1 [, int parameter2 [, int parameter3]]]) The filters described here were written for the PHP-bundled build of GD, and may not be available in other releases.

Special effects using imagefilter()

This is quite an odd function, as it happens, because the number of arguments you need to pass to it vary depending on the effect. The best way to explain this function is simply to explain briefly how it works then show a code example, so let's get started straight away. No matter what, the function returns true if the filter was applied successfully and false otherwise. First up is IMG_FILTER_BRIGHTNESS, which takes a number between -255 and 255 that represents how much you want to brighten or darken the image.

Optimization

Htaccess. Htaccess tester.