A blend of programming and seo

Posts from — May 2009

Embedding flash movies made easy

There are a few way to embed a flash object or movie in a webpage:

1) Default code from adobe

It consists of an Object tag with an Embed tag placed inside it. This is the most popular Flash embed method and is the default choice when publishing your Flash movie from the Adobe Flash IDE. This is the most compatible way to embed a Flash movie, and will work in the widest range of browsers.

2) A separate flash movie

This method involves placing a Flash movie on the index page of your website, and this Flash movie then checks the versopm variable in the Flash player and redirects the user either to the Flash content inside the site, or an upgrade page.

Issues to consider with this method

  • It will damage your search engine positioning – Since you are now using your index page as an empty Flash detection page, when people search for you in Google or other search engines, many times, the description text ends up showing up as “Detecting Flash Player” or even no description at all.
  • It is not valid HTML or XHTML

3) The Adobe Flash Player Detection Kit

Adobe has a flash detection kit that comes with Flash versions 8 and higher.

Issues to consider with this method

  • Not very user friendly
  • has the same issues as #2

A better solution is to use SWFObject, a Javascript Flash Player detection and embedding script.

The script can detect the Flash plug-in in all major web browsers (on Mac and PC) and is designed to make embedding Flash movies as easy as possible. It is also search engine friendly, degrades gracefully, can be used in valid HTML and XHTML 1.0 documents.

SWFObject works in all the current web browsers, including, on PC: IE5/5.5/6, Netscape 7/8, Firefox, Mozilla, and Opera. On Mac: IE5.2, Safari, Firefox, Netscape 6/7, Mozilla, and Opera 7.5+.

How to use it

Usage is straight-forward and simple. Include the swfobject.js Javascript file, then use a small amount of Javascript on your page to embed your Flash movie. Here is some example code:

<script type="text/javascript" src="swfobject.js"></script>
       
<div id="yourcontent">
  This text is replaced by the flash object
</div>

<script type="text/javascript">
   var so = new SWFObject("test.swf", "mymovie", "400","200","8","#FFFFFF");
   so.write("yourcontent");
</script>

Here is a description of its parameters:

var so = new SWFObject(swf, id, width, height, version, background-color [, quality, xiRedirectUrl, redirectUrl, detectKey]);

Create a new SWFObject and pass in the required arguments:

  • swf – The file path and name to your swf file.
  • id – The ID of your object or embed tag. The embed tag will also have this value set as it’s name attribute for files that take advantage of swliveconnect.
  • width – The width of your Flash movie.
  • height – The height of your Flash movie.
  • version – The required player version for your Flash content. This can be a string in the format of ‘majorVersion.minorVersion.revision’. An example would be: “6.0.65″. Or you can just require the major version, such as “6″.
  • background-color – This is the hex value of the background color of your Flash movie.

Optional arguments are:

  • quality – The quality you wish your Flash movie to play at. If no quality is specified, the default is “high”.
  • xiRedirectUrl – If you would like to redirect users who complete the ExpressInstall upgrade, you can specify an alternate URL here.
  • redirectUrl – If you wish to redirect users who don’t have the correct plug-in version, use this parameter and they will be redirected.
  • detectKey – This is the url variable name the SWFObject script will look for when bypassing the detection. Default is ‘detectflash’. Example: To bypass the Flash detection and simply write the Flash movie to the page, you could add ?detectflash=false to the url of the document containing the Flash movie.

The latest version can be downloaded here

May 14, 2009   3 Comments

How to turn a php script to an exe..for free

There are a few commercial products out there that allow you to turn your php scripts into an executable. While most of them work well, I have found a way to do it for free, using an open source application. This application is called Wapache (based on the apache web server) and it is open source (distributed under the Apache License 2.0).

WApache doesn’t convert your script directly into an executable, it runs on the combination of a windows app (which uses an embedded IE control) and a stripped down version of apache.

Features

  • No Internet Explorer menu, tool bar, or address bar.
  • Precise control over placement of windows
  • Three types of windows: basic, tool windows, and dialog boxes (modal and modeless)
  • Fully customizable drop-down and context menu
  • System Tray integration
  • Asynchronous data handling
  • Works with standard Apache modules like mod_php and mod_perl

screenshot

wapache screen How to turn a php script to an exe..for free
(this is a screenshot of wapache running phpmyadmin)

How to turn your php script into an executable

1) copy all of your scripts/files into the htdocs directory (make sure that the main file is called index.php)
2) launch bin/wapache.exe
3) you will now see your php script in the application that is running

There is also many options that allow you to configure the app in many different ways. This can be found on line 100 of conf/default.wcf (documentation for this config file can be found here):

<StandardWindow Main>
    HorizontalAlign Center
    VerticalAlign Middle
    Height 60%
    Width 60%
    3DBorder Off    
    IconPath "../icons/lightbulb.ico"
</StandardWindow>

This could be used for a demo/trial of a web application. A windows installer could also be used (NSIS works well and is free) to create a fully installable, desktop application.

Since this only relies on the apache web server, it’s also possible to use this with any type of supported scripts.

Download

The latest version of Wapache can be found here

May 13, 2009   3 Comments

How to use the digg API

digg How to use the digg API

This article will show you how to use the digg API using PHP. I have also written a library in PHP that maps all of the endpoints documented in the API to easily accessible functions (it is also compatible with PHP 4).

What can you do with the digg API?

  • Get all popular stories submitted after January 1, 2007 sorted by promotion date
  • Get the most recent 100 upcoming stories in the topic “Apple”
  • Get the first 20 stories that were promoted on or after December 25, 2005
  • Determine whether a story, identified by its URL, has been submitted to Digg and, if so, get details like the number of Diggs and comments it has received
  • Get the details of a story, identified by its URL on Digg
  • Get all stories submitted today from nytimes.com
  • Get all stories submitted by Kevin Rose (or another Digger)

How it works

Requests are sent to the digg servers through URLS that are described in the API doc (here).

Here is an example:

http://services.digg.com/stories?appkey=http%3A%2F%2Fexample.com

This will return all stories. By default only 10 will be returned at a time (which can be increased to a maximum of 100). Also, you may notice an appkey=XXX argument. This is a unique identifier required by the digg servers. It is recommended to use the urlencoded refereral URL. Other return types are also available, which can make parsing easier depending on the language used.

response types:

  • XML: Easily parsed in many languages on many platforms. It is particularly easy to use in Flash applications.
  • JSON: May be directly eval’d in Javascript, and also can be parsed in many languages.
  • Javascript: Useful as the source of a script tag, it passes JSON response to the Javascript callback function you specify.
  • Serialized PHP: Easily unserialized in PHP to create objects, to which the programmer can attach custom methods. Or the programmer can directly access the response data through the public properties of the objects.

example:

http://services.digg.com/stories?appkey=http%3A%2F%2Fexample.com (will return XML by default)
http://services.digg.com/stories?appkey=http%3A%2F%2Fexample.com&type=json
http://services.digg.com/stories?appkey=http%3A%2F%2Fexample.com&type=php
http://services.digg.com/stories?appkey=http%3A%2F%2Fexample.com&type=javascript

Other basic arguments

    count
    Number of events to retrieve.
    Event count integer
    Default: 10, Maximum: 100.
    offset
    Offset in complete events list.
    Event offset integer.
    Default: 0.

PHP code

The following is a function that will allow you to connect to the digg service and parse the results. It also will automatically generate the appid based on the current location of the script.


function connect($hostname) {
    //this is an ID that is unique to your app.  It is auto-generated, based on the calling URL
    $appid = urlencode(&quot;http://&quot;.$_SERVER[&quot;HTTP_HOST&quot;].$_SERVER[&quot;REQUEST_URI&quot;]);
   
    $host = $hostname.&quot;&amp;appkey=&quot;.$appid;
    echo $host;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_URL,$host);
    curl_setopt ($ch,CURLOPT_USERAGENT,"Test library");
    curl_setopt ($ch,CURLOPT_CONNECTTIMEOUT,60);
    $response = curl_exec ( $ch );
    curl_close($ch);
   
    return $response;
}


Download

The digg API toolkit can be downloaded Here

May 6, 2009   7 Comments

2-way encryption in PHP

For most php applications, a 1-way hash such as md5 or sha1 is sufficient for storing passwords in a database. This is more secure, because passwords aren’t stored in plaintext and when a user does type in a password to login to the application, it is compared to a hash rather than the actual password. A problem with this method is that there is no way to get the original password. So if a user forgets their password, the only thing that you can do is reset (by generating a new one) it and send them this new password.

Reasons you might need the original password:

  • You are communicating with an external service such as twitter
  • It is more convenient to your users to send them their original password (although, this is slightly more insecure, because email is plain-text, and many users use the same password for multiple apps)

Built-in functions (requires mcrypt extension)

PHP has built-in functions for 2-way hashing called mcrypt. It supports: DES, TripleDES, Blowfish (default), 3-WAY, SAFER-SK64, SAFER-SK128, TWOFISH, TEA, RC2 and GOST in CBC, OFB, CFB and ECB cipher modes,RC6 and IDEA.

Example of usage:

<?php
$key = "your key";
$input = "data to be encrypted";

$encrypted_data = mcrypt_ecb (MCRYPT_3DES, $key, $input, MCRYPT_ENCRYPT);
?>

The following is a class written all in PHP that supports AES 128 2-way encryption. The nice part, is that you don’t need any external libraries to use it.

Here is an example:

<?php
 require_once('aes128.php');
 $aes=new aes128();
 
$cipher=$aes->makeKey("0123456789abcdef");

//encrypt data using above cipher
 $encPassword=$aes->blockEncrypt("secretpass",$cipher);

//decrypt password using above cipher
 $decPassoword=$aes->blockDecrypt($encPassword,$cipher);   
 echo $decPassoword;
?>

Download here

May 5, 2009   6 Comments

5 ways to extend firefox tabs

The following are 5 Firefox extensions that will extend tab functionality.

1) IE tabs

ietab 5 ways to extend firefox tabs

This is a great tool for web developers that allows you to view web pages in Internet Explorer within a firefox tab.

Download Here

2) Informational tab

informtab 5 ways to extend firefox tabs

This extension provides thumbnail-style preview for each tab, does progress meter, and indicates unread status.

Download Here

3) Tab Mix Plus

tabmix 5 ways to extend firefox tabs

Tab Mix Plus enhances Firefox’s tab browsing capabilities. It includes such features as duplicating tabs, controlling tab focus, tab clicking options, undo closed tabs and windows, plus much more. It also includes a full-featured session manager with crash recovery that can save and restore combinations of opened tabs and windows.

Download Here

4) TabSidebar

Features:

  • Provides navigation options for each tab including history, stop and reload.
  • Allows you to move tabs around with drag and drop.
  • You can drop links, local files and bookmarks anywhere you like in the tab list.
  • Displays the security status of tabs.
  • Automatically refreshes the tab preview whenever the page changes.
  • Lets you hide the main tab bar when the sidebar is open.
  • Bidirectional support making the sidebar work correctly in right-to-left languages.
  • Works well with other tab-related extensions allowing you to use their context menu additions from the sidebar.

Download Here

5) Tab Effect

tabeffect 5 ways to extend firefox tabs

This adds a tab switching cube effect to Firefox.

Download Here

May 4, 2009   No Comments