Simple, On-The-Fly Image Resizing in PHP

Recently, I installed WordPress and a theme that used an image resizer extension called “TimThumb“. It turns out it’s actually pretty fast and useful. For example, if you have an image on your server called “castle1.jpg”, you can display it in your website as usual using

[cc lang=”html”][/cc]

and, if you want to resize it without having to go into Photoshop, resizing it, uploading it to your server, using TimThumb, you can just do this: Read More

Ways to Improve Website Performance

Here are a couple of different ways to improve website performance using 3rd party services:

  • Google PageSpeed Service
    Page Speed Service New! is an online service to automatically speed up loading of your web pages. Page Speed Service fetches content from your servers, rewrites by applying web performance best practices and serves it to end users via Google’s servers across the globe.
    This is a paid service
  •  Amazon CloudFront CDN
    Upload and deliver website components such as images, videos, audio, javascript, etc from Amazon’s cheap CDN
    This is a pay-per-use service
  •  Yotta Site Speed Optimizer
    Similar to Google PageSpeed Service
    This is a paid service
  • CloudFare
    Free to paid

Global Economic Crisis

By now, many of you have probably noticed that the economic crisis that started back in 2008 isn’t over and doesn’t seem to be ending any time soon. Furthermore, demonstrations are taking place more and  more all around the world. Corrupt governments all over the Middle East are being toppled. If you haven’t already done so, I highly suggest you watch some or all of the following videos to learn the real cause of the economic meltdown the world is going through. The more informed you are, the better we can be at preventing governments and Wall Street from letting it happen again.

A Better PHP Redirect Method

PHP provides the header( ) function for redirecting users to another page, e.g.

[cc lang=”php”]header(“Location: http://www.google.com”);[/cc]

but, in case that doesn’t work, here’s a custom method that will attempt to redirect your users in 3 different ways:

[cc lang=”html”] function redirect($target) {
if (!headers_sent()) {
header(“Location: $target”);
}

echo “n”;
echo “document.location = ‘” . $target . “‘;n”;
echo “

If you are not automatically redirected, please click here“;
exit;
}
[/cc]

then, you can redirect using this new function like this

[cc lang=”php”]redirect(“http://www.google.com”);[/cc]

How to Include Server Request URI in PHP Error Log

Having an error log in PHP is great because it allows you to see errors without showing them to your users. But, it’s often very difficult to fix errors without knowing what page a user was viewing that generated the error. Here’s some code that you can add to your PHP website to include the server request URI in your error log.

[cc lang=”php”]/* *************************/
/* HANDLE NON-FATAL ERRORS */
/* *************************/
function debugErrorHandler($errno, $errstr, $errfile, $errline)
{
if (error_reporting()!==0) {
switch ($errno) {
default:
error_log(“PHP Warning Debug: Server Request URI: ” . print_r($_SERVER[“REQUEST_URI”], true));
break;
}

return false; // false -> Execute PHP internal error handler
}
}

set_error_handler(‘debugErrorHandler’);

/* *************************/
/* HANDLE FATAL ERRORS */
/* *************************/
function shutDownFunction() {
# Using error_get_last is the “right” way, but it requires PHP 5.2+. The back-up is a hack.
if (function_exists(‘error_get_last’)) {
$lastPHPError = error_get_last();
$phpFatalError = isset($lastPHPError) && $lastPHPError[‘type’] === E_ERROR;
} else {
$phpFatalError = strstr($output, ‘<b>Fatal error</b>:’) && ! strstr($output, ‘</html>’);
}

if ($phpFatalError)
error_log(“PHP FATAL Debug: Server Request URI: ” . print_r($_SERVER[“REQUEST_URI”], true));
}

register_shutdown_function(‘shutDownFunction’);[/cc]

Add this to the top of your PHP pages (by including it) and you’ll see the server request URI in your error logs.

PHP New Line Breaks n

Recently, I needed to create a new line in a containing multiple lines of text using PHP. I thought I could just do

[cc lang=”php”]$message = ‘abcde n’;[/cc]

but, apparently PHP interprets that as a literal  slash followed by the letter n. The trick is you need to use double-quotes to get the new line to show up, as in

[cc lang=”php”]$message = “abcde n”;[/cc]

How To Add SEO Keywords to a Website Without Cluttering it up

Adding keywords optimized for search engines is extremely important for getting good rankings in Google. But, what do you do when your website’s home page or any other page looks exactly the way you want it without many keywords or you prefer it to mainly contain photos with little text. Well, here’s a “white-hat” way of adding a bunch of text with keywords to your site which will get noticed by Google but not so much by your visitors.  Read More

Different Ways to Use a 404 File-Not-Found Handler

1. Redirect to a File Not Found page
If a file doesn’t exist, you can redirect your users to a page saying so.

2. Redirect to the correct location of a file
If, for example, your server treats file names with case sensitivity turned on, then a request to abc.php and Abc.php will be different. If all your file names are in lowercase, then a request to Abc.php will return file not found. Fix this Read More

Steve Jobs : 1955 – 2011

I’m still using a PC but I do have an iPhone 🙂

Enjoy heaven! You’ll surely be missed.

Bye …

Reset Your CSS For Equal Display in All Browsers

As you probably know, browsers have their own default CSS styles which determine how a web page looks such as the spacing between elements and how form fields look. To save yourself from the headache of trying to fiddle with CSS settings to get your websites to look right in all browsers, add the following CSS reset code to the top of your CSS file.
[cc lang=”css”]/* reset / remove browser defaults */
body, div, h1, h2, h3, h4, h5, h6, p, ul, ol, li, dl, dt, dd, img, form, fieldset, input, blockquote {
margin: 0px;
padding: 0px;
border: 0px;
font-weight: normal;
}[/cc]