Boolean

Image Placeholders

placekitten

A quick and simple service for obtaining pictures of kittens for use as placeholders in your designs or code.

Simply place the required image size after their url (for example http://placekitten/200/300) and you will be rewarded with a cute placeholder image. Great for quick real code mockups…

Check it out here

Image Placeholders Read More »

cURL in PHP to access protected sites

So I was trying to use the FaceBook PHP-SDK and ran into an issue. As the cURL was pointing to an HTTPS source I was getting this error:
Failed: Error Number: 60. Reason: SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

The problem was that cURL hasnt been configured to trust the servers HTTPS certificate, as by default cURL is not setup to trust any of the Certificate Authorities (CAs)
Browsers dont have this issue as the browser developers were kind enough to include a list of default CAs, however this doesnt help us out at all…

A quick fix is to simply configure cURL to accept any server certificate. Obviously from a security point of view this isnt great, but if you are not passing sensitive information back and forth you should be ok.

Before calling curl_exec() add the following code:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
This causes cURL to blindly accept an server certificate without doing any verification with the CA that issued it.

The Proper Fix
The proper fix is slightly more involved so I plan to cover it at a later stage. If you cant wait that long research the curlopt_cainfo parameter, and obtaining (and saving) a CA certificate to enable cURL to trust it.

cURL in PHP to access protected sites Read More »

Reading GET variables with JavaScript

Recently I needed a JavaScript implementation of PHP’s $_GET functionality. There are a lot of quite bulky solutions out there, but my favourite was by Josh Fraser here

<script type="text/javascript">
function $_GET(q,s) {
s = (s) ? s : window.location.search;
var re = new RegExp('&'+q+'=([^&]*)','i');
return (s=s.replace(/^\?/,'&').match(re)) ? s=s[1] : s='';
}
</script>

Short, simple, effective. Enjoy.

Reading GET variables with JavaScript Read More »

Five Star Linked Data

The vision of the Semantic Web is to create both connected and interlinked data which can be shared and reused by all. In 2006, Sir Tim Berners-Lee introduced a notion of linked data and the best practices for creating and sharing on the Web. To encourage people (and government) to share data he additionaly developed a rating system:

* Available on the web in any format, but with an open licence
** Available as machine readable structured data such as Excel
*** As for two stars, but in an open format such as CSV
**** As for three stars but using open standards from W3C to identify
***** All the above but additionally linking your data to other peoples to provide context

There are some badges available here to display on your site if you wish to display your commitment
Cafepress has official W3C merchandise available here

In the holiday downtime it is good to think about some of the ways we can make a real difference in amongst those cool drinks at the beach (or snow shovelling in the Northern Hemisphere)

Five Star Linked Data Read More »

iPhone WordPress Application Configuration

Wordpress Logo
On a self hosted WordPress installation (not a wordpress.com or .org) I was being continually rebuffed by an incorrect username/password combination – and I knew my password was correct.
Was it a problem with the iPhone application itself, or was my blog mis-configured?

The solution as it turns out was reasonably simple:

From your WordPress installation admin control panel: under Settings -> Writing in the Remote Publishing section ensure there is a tick in the checkbox

XML-RPC – Enable the WordPress, Movable Type, MetaWeblog and Blogger XML-RPC publishing protocols.

After that, you should be able to add the site from the iPhone app. Good luck!

iPhone WordPress Application Configuration Read More »

FTP credentials in WordPress

Wordpress Logo

The issue is that when you try to automatically update your WordPress installation you are asked to supply your ftp login credentials. Hopefully just like me you are using unique, complex and hard to remember details. Joost De Valk created a plugin to fix the automatic update issue that some webhosts have here

The plugin (and this alternative) are a way to avoid having to go look up the details before plugging them in every time you wish to update.

In your wp-config.php you can define these values to hopefully end this problem once and for all:

define('FS_METHOD', 'ftpext');
define('FTP_BASE', '/path/to/wordpress/');
define('FTP_USER', 'username');
define('FTP_PASS', 'password');
define('FTP_HOST', 'host');
define('FTP_SSL', false);

The codex has a little more to say on the matter here

FTP credentials in WordPress Read More »

Renaming WordPress database prefixes

Wordpress Logo

Having non-standard table prefixes can help reduce automated attacks and malicious scripts from compromising your WordPresss database

This is a fairly simple process if you are familiar with the underlying database and principles, but is not recommended unless you are experienced with queries and a sql client such as phpMyAdmin

1) Prepare by making a backup everything, redirect your visitors etc
2) Change the default table prefix in wp-config.php to your required name
3) Rename all WordPress database table prefixes

Here are the necessary SQL commands (remember to change the example to your own table prefix)

RENAME table 'wp_commentmeta' TO 'wp_rand0mstr1ng_commentmeta';
RENAME table 'wp_comments' TO 'wp_rand0mstr1ng_comments';
RENAME table 'wp_links' TO 'wp_rand0mstr1ng_links';
RENAME table 'wp_options' TO 'wp_rand0mstr1ng_options';
RENAME table 'wp_postmeta' TO 'wp_rand0mstr1ng_postmeta';
RENAME table 'wp_posts' TO 'wp_rand0mstr1ng_posts';
RENAME table 'wp_terms' TO 'wp_rand0mstr1ng_terms';
RENAME table 'wp_term_relationships' TO 'wp_rand0mstr1ng_term_relationships';
RENAME table 'wp_term_taxonomy' TO 'wp_rand0mstr1ng_term_taxonomy';
RENAME table 'wp_usermeta' TO 'wp_rand0mstr1ng_usermeta';
RENAME table 'wp_users' TO 'wp_rand0mstr1ng_users';

Remember if there are other WordPress related tables created by plugins you will need to rename these as well. ALL table prefixes should be renamed.

4) Search the options table for any instances of the old table prefixes

SELECT * FROM 'wp_rand0mstr1ng_options' WHERE 'option_name' LIKE '%wp_%'

This will return wp_user_roles and any options or configurations created by plugins or custom scripts. Update the fields as appropriate.

5) Edit the usermeta table

Search the usermeta for all instances of the old table prefixes

SELECT * FROM 'wp_rand0mstr1ng_usermeta' WHERE 'meta_key' LIKE '%wp_%'

Again these fields will need to be updated where appropriate

Test everything is working and then set your site to live once again.

Renaming WordPress database prefixes Read More »

PHP URL Shortening


A current Twitter related project involves quite a few URLs and because Twitter limits you to only 140 characters per post shortening a link can be very rewarding.

There are a multitude of URL shortening services on the internet and whilst perhaps not producing the shortest links, TinyURL.com requires no account in order to use it via PHP which makes for a very simple query:
function getTinyUrl($url) {
return file_get_contents("http://tinyurl.com/api-create.php?url=".$url);
}

bit.ly is another popular URL shortener, however it does require an easily obtainable API key. The code is below:
function getBitly($url) {
$query = file_get_contents("http://api.bit.ly/v3/shorten?login=YOUR_LOGIN&;apiKey=YOUR_APIKEY&longUrl=".$url."&format=xml");
$element = new SimpleXmlElement($query);
$bitlyurl = $element->data->url;
if($bitlyurl){
return $bitlyurl;
} else {
return '0';
}
}

Don’t forget to change YOUR_LOGIN and YOUR_APIKEY to your own values. I’m sure you don’t need any help with usage, but as always comment if you have any issues.

PHP URL Shortening Read More »