Month: October 2009

Dont copy variables without reason


Sometimes PHP novices attempt to make cleaner or more legible code by copying predefined variables to variables with shortened names prior to working with them. This actually results in doubled memory consumption (when the variable is altered) and therefore slower scripts. In the following example, if a user had inserted 512KB worth of characters into a textarea field this would result in nearly 1MB of memory being used.

$title = strip_tags($_POST['title']);
echo $title;

This operation can be performed inline, – avoiding the memory overhead.

echo strip_tags($_POST['title']);

PHP Twitter Class


Twitter is a service for friends, family, and co-workers to communicate and stay connected through the exchange of quick, frequent answers to one simple question: What are you doing?

PHP Twitter is a (wrapper)class to communicate with the Twitter API written by Tijs Verkoyen. Download page is available here

A quote from the author (and he’s not wrong) The class is well documented inline. If you use a decent IDE you’ll see that each method is documented with PHPDoc. There is also a tutorial available here

So, to sum up, these links should kickstart your twittering ability from PHP (and your website).

Happy tweeting!

301 Redirects

A 301 redirect is an efficient and Search Engine friendly method for webpage redirection. It is relatively simple to implement and it should preserve search engine rankings for that particular page should you need to rename or move it. The code “301” is interpreted as “moved permanently”.

There are multiple ways depending on your server and scripting platform, however I will deal with ones most relevant to Boolean clients.

PHP page level redirects:

Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location:" );

.htaccess domain level redirects (Apache Mod-Rewrite moduled must be enabled)

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*)$1 [R=301,L]

You can test your redirection with the Search Engine Friendly Redirect Checker available here.