Ajax applications with PHP

It’s about time that the open source community take on Ajax.  Check out xajax.

Ajax, or AJAX, is a web development technique used for creating interactive web applications. The intent is to make web pages feel more responsive by exchanging small amounts of data with the server behind the scenes, so that the entire web page does not have to be reloaded each time the user requests a change. This is intended to increase the web page’s interactivity, speed, functionality, and usability.

Live HTTP Headers plugin for Firefox

Have you ever had the need to watch and inspect HTTP headers in real time while pages are being downloaded from the Internet? If you develop web applications or sites, I’m sure you have.

If so, check out the Live HTTP Headers plugin for Firefox. Not only will it capture what’s currently being downloaded, but it allows you to replay what was captured for simulation purposes, e.g., when you need to find out what arguments and values are needed to POST to a web page.

Here are some screenshots:

Fig. 1.1 – Live HTTP Headers Page Info tab

Fig. 1.2 – Live HTTP Headers Replay Window

I’m sure you will find this plugin/tool very helpful. Take care. =0)

Automatically redirect to HTTPS with .htaccess

I caught the flu last week that’s why I haven’t been posting regularly.  =0(

Anyway, I wrote previously on how to password-protect a website/page, but in this post I’ll show you how to redirect a user automagically to HTTPS.

All you need to do is add the following in the .htaccess file (I’ll be using the Squirrelmail website as an example):

1.  I use Apache 2, so I do:

vi /etc/httpd/conf.d/squirrelmail.conf

Initially, it will look like:

# SquirrelMail is a webmail package written in PHP.
Alias /webmail /usr/share/squirrelmail
<Directory /usr/share/squirrelmail>
    Options FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

2.  Add the following, like so:

# SquirrelMail is a webmail package written in PHP.
Alias /webmail /usr/share/squirrelmail
<Directory /usr/share/squirrelmail>
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*)
https://%{HTTP_HOST}%{REQUEST_URI}
    Options FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

3.  Save and exit by typing :wq!.

4.  Restart Apache like so: service httpd restart.

That’s it!  When someone visits, http://www.website.com/webmail, Apache will automatically redirect the user to https://www.website.com/webmail.

Hope this helps.  Take care!

Creating a self-signed cert

If you need to support or serve your website using SSL, but only for personal purposes, such as a webmail, you’ve probably come across the problem of creating your own server certificate.

Secure Sockets Layer (SSL), are cryptographic protocols which provide secure communications on the Internet for such things as web browsing, e-mail, Internet faxing, instant messaging and other data transfers.

If so, run the following to create a self-signed cert:

1.   Via a terminal window, run these commands in sequence:

openssl genrsa -out server.key 1024
openssl req -new -key server.key -out server.csr
openssl rsa -in server.key -out signingkey.key
openssl x509 -in server.csr -out selfsigned_digicert.crt -req -signkey signingkey.key -days 3650
chmod 600 server.key
chmod 600 selfsigned_digicert.crt
mkdir -p /etc/pki/tls/private
mkdir -p /etc/pki/tls/certs
cp server.key /etc/pki/tls/private/localhost.key
cp selfsigned_digicert.crt /etc/pki/tls/certs/localhost.crt

1.   Restart HTTP (I run FC6), like so:

server httpd restart

That’s it!  You can now serve your website via SSL…Don’t forget to open up your firewall to accept them (TCP port 443).

Bad-Behavior MediaWiki Plugin Fix

If you use MediaWiki to power your wiki, you’ve probably heard of the Bad-Behavior plugin to help fight spam.

Bad Behavior is a set of PHP scripts which prevents spambots from accessing your site by analyzing their actual HTTP requests and comparing them to profiles from known spambots. It goes far beyond User-Agent and Referer, however. Bad Behavior is available for several PHP-based software packages, and also can be integrated in seconds into any PHP script.

I was all for it after I read the description as well as the functions it adds to one’s wiki.  So, I did the following:

1.   Downloaded it like so:

wget http://www.bad-behavior.ioerror.us/download/bad-be…

2.   Unzipped it with the -a option (for ASCII mode):

unzip -a bad-behavior-2.0.10.zip

3.   Copied the whole folder to /path-to-wiki/extensions

cp -R /path-to-wiki/extensions

4.   Edited LocalSettings.php an added the following line at the end of the file:

include( ‘./extensions/Bad-Behavior/bad-behavior-mediawiki.php’ );

The include statement above should’ve worked where a new table would’ve been added in my MediaWiki DB, but this did not happen, and when clicking on any link, I would just get a blank page.

My HTTPD logs also showed “undefined variable” errors, so after searching for fixes, I found that the following line had to be added just below the require_once(“includes/DefaultSettings.php”) line to resolve the issues. 

Apparently, you’ll need this if you’re using a certain combination of Apache-PHP-MediaWiki versions:

require_once( “includes/DatabaseFunctions.php” );

I restarted Apache and all worked fine.  You can also add the Bad-Behavior 2 Extended extension if you’d like, which I did.