Archive for PHP

Nov 12

Valid, Browser Specific CSS Properties

Everyone has had to use a hack or two to get their site to display the same in all the major browsers. 99% of the time Internet Explorer is screwing with something. The problem is, using “hacks” like * html .className makes your CSS invalid. Some people are bothered by this, others don’t care (as long as it works, its fine by me).

One solution is to parse the user agent with PHP and determine which browser the visitor is using. We can then format that information however we would like and apply the CSS tags to any element on our site. The easiest would be to add these custom tags to the tag and only have to reference it in one place.

Nov 05

5 Built-In PHP Shortcuts to Optimize Your Code

Everyone wants to make the neatest code possible, but sometimes things can get out of control and you end up with an illegible mess. Here are a few tricks I use to clean up my code.

1. Ternary If Statements

I use this the most, I would say I use it at least once for any script I write. Very useful for adding classes to multiple elements and specifying the last element in the bunch. Or alternating between even and odd rows.

Nov 03

Add Watermarks to a Directory of Images

One of the biggest issues on the internet is protecting your media. You could disable right click or try other forms of trickery, but if someone wants your image, they are going to get it somehow. The best way to protect your images is to add a watermark.

You can add a watermark yourself — image by image — or use PHP’s GD library to do it for you automatically. Its a lot easier then you probably think.

All we need from the .htaccess file is to direct any requests (aside from image.php) to image.php to do all the work.