Archive for the ‘Web Development’ Category
Configuring CakePHP on RackSpace Cloud
CakePHP is a great application framework for “developing rapid websites”. I’ve started building quite a few websites with the system and become quite fond of the MVC framework, the native built-in functionality and vast amount of support available.
When I came to setup an application on RackSpace Cloud Sites (previously known as Mosso), due to the unique way the server was configured (running both Apache and IIS simultaneously), CakePHP didn’t want to work straight out the box.
It was only after quite few hours of research and live chat from the hosting support team that I discovered there were several tweaks that had to be made for CakePHP to work on the Rackspace Cloud.
Basically, it all comes down to the .htaccess files and RewriteBase.
- In the route .htaccess file, add the following line:
<IfModule mod_rewrite.c> RewriteEngine on RewriteBase / # Cake Defaults RewriteRule ^$ app/webroot/ [L] RewriteRule (.*) app/webroot/$1 [L] </IfModule>
- In the app folder, add the following line to your .htaccess file:
<IfModule mod_rewrite.c> RewriteEngine on RewriteBase /app RewriteRule ^$ webroot/ [L] RewriteRule (.*) webroot/$1 [L] </IfModule>
- In the app/webroot folder, add the following line to your .htaccess file:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase /app/webroot RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php?url=$1 [QSA,L] </IfModule>
That should do it.
Posting PayPal forms with PHP
PayPal is a great system for integrating simple shopping cart functionality on a website. Whether your website sells a large number of products or offers simple subscription or donation forms, PayPal allows your users to send you money securely, safely and quickly without you needing to setup a full merchant account with your online banking. With millions of eBay users already holding PayPal accounts, its the obvious choice for any online service requiring payment.
Recently, I was building a system which required the user to fill in their personal details in a form on a website before being sent to PayPal to arrange payment. There weren’t many solutions available online so, when I asked on Twitter for some help, Drew suggested just appending the required form variables to a URL querystring with a simple GET request in your header which would then be encoded on PayPal’s end to avoid (some) tampering.
You know what - it worked. Here’s the necessary code:
<?php
$data = 'cmd=_xclick';
$data .= '&no_note=1';
$data .= '&no_shipping=1';
$data .= '¤cy_code=GBP';
$data .= '&amount=' . $total_cost;
$data .= '&item_name=' . urlencode('Your Product Name');
$data .= '&business=' . urlencode('your.email@yourwebsite.com');
$data .= '&return=' . urlencode('http://yourwebsite.com/confirmation.php');
$data .= '&cpp_header_image=' . urlencode('http://yourwebsite.com/images/logo_paypal.gif');
header("Location: https://www.paypal.com/cgi-bin/webscr/?" . $data);
?>
This is a very basic adaptation of what PayPal can do - I’ve completely overlooked the IPN confirmation side of things (which would be highly recommended to confirm the amount hadn’t been tampered with).
Upgrading WordPress via SSH
WordPress is quite a popular open source CMS that is often praised for its ease of use and simple installation. Like most open source applications, WordPress tends to have upgrades every few months to improve security, stability and the underlying framework.
In recent versions of WordPress, this process has been extremely easy with an automatic upgrade system (something that has also been integrated into the plugin framework too) but on older versions, the process wasn’t particularly straight forward.
Thankfully, I found a rather useful set of commands that you can run on your server via SSH to make this process extremely simple.
Disclaimer: I recommend you always take a backup of the database and working folder before running these commands in case something goes wrong. 99% of the time, I’ve not had any problems with this process but it’s better to be safe than sorry.
# Get the latest WordPress version available. wget http://wordpress.org/latest.tar.gz # Uncompress it. tar xfz latest.tar.gz # Delete the old wp-includes and wp-admin directories. rm -rf ./wp-includes/ rm -rf ./wp-admin/ # Go to the new Wordpress directory: cd wordpress/ # Copy the downloaded files to your existing WP install, overwriting any old files. cp -rpf -f * ../ # Remove the uncompressed and downloaded files. cd .. rm -rf ./wordpress/ rm -f latest.tar.gz # Visit your blog and upgrade the database (if needed).
Make sure you visit your WordPress installation in the browser straight away to run any upgrade scripts that are required. You should only see one screen and that process is complete.
IMDB Vote History as RSS
Over the last few years, I’ve been using IMDB to keep a record of the movies I’ve watched by giving them a rating out of ten using the simple star rating widget at the top of each movie page.
By rating each movie, I have managed to create quite an extensive history of the movies I’ve seen which is publicly available on my personal vote history page.
The problem I’ve had though is accessing that data elsewhere for use on other websites, such as this blog, Twitter or Facebook profile.
Until now, I’ve been using a service called Dapper which can scrape any accessible webpage for data and output that data as a range of different source such as RSS, Atom, JSON or XML.
The RSS output has actually worked quite well but the Dapper service was quite tempramental at keeping up-to-date, sometimes taking a few weeks to update. It wasn’t ideal for a reliable source.
Well, I discovered this morning that IMDB actually offer a dedicated RSS feed directly from their website of this exact data.
If you have been publishing your vote history to a public page, you can see your feed by appending your unique reference to the end of the URL http://feed://rss.imdb.com/mymovies/list?l=[your id].
For example, my vote history would be accessible at http://rss.imdb.com/mymovies/list?l=5051158.
Unfortunately, the date saved doesn’t seem to be output as the timestamp for each RSS item but I’m sure a few pokes at the IMDB development team could sort that out.
No doubt there are other personalised RSS feeds available from IMDB such as your movie reviews and favourites. If I find any, I’ll add them to this post.
Maybe now, I can tap into the data and start building some useful widgets out of it.
Update: it seems there is already a Facebook app which taps in to your vote history called My Movies.






