Monday 12 October 2009

Learning PHP - Examining Variable Types

Programming is all about data and most languages take some trouble over classifying what kind of data they are working with. PHP's classes of data type are:
  • Integer
  • Float
  • Boolean
  • Array
  • Object
  • Null
  • Variable
PHP is described as being weakly or dynamically typed. This simply means that it works out the data type by looking at it rather than by you assigning it. For example:
  • $IssueNumber="0"; assigns integer type
  • $formulationpercentage="0.00"; assigns float type
Variables can be quickly reassigned to a new type. For instance if you add the line $IssueNumber="hello" it would be reassigned to a string type. This ability to change file types on the fly can be extremely useful.

Type Casting
You can pretend that a variable or a value is of a different type by using a type cast. All you have to do is put the temporary type in brackets in front of the variable you are interested in.
  • $IssueNumber="0"; assigns integer type
  • $formulationpercentage=(float)$IssueNumber
The second line takes the value stored in IssueNumber , interprets it as a float and stores it in fomulationpercentage.

Variable Variables

PHP provides one other type of variable. Variable variables enable you to change the name of a variable dynamically.

PHP - Introduction

There was a time that if you wanted to learn any serious programming you had to invest in an expensive shrink-wrapped box of some language or other. You can still do that if you want to, but the open source movement has removed one of the barriers to entry by making a number of seriously useful programming languages available to anybody with the time, energy and determination to master them. Of course, having the time, energy and determination is far harder than writing a cheque so programming is still something that not everyone gets around to doing or indeed would want to. But if you do, PHP is one such freely available resource. I have decided that I want more control over my blogs and website so I am going to try and learn PHP. You are welcome to come along for the ride.

Saturday 22 November 2008

GIMP - A bit fiddly but very powerful

It sometimes comes as a bit of a shock to people who don't give a lot of thought to computers to find that the ferocity of the Mac versus Windows debate rivals the controversy over the religious principles in the Reformation. You read some forums and breathe a sigh of relief that it is no longer legal to burn people at the stake. Even if you are au fait with the passions aroused by these different platforms, you may not be aware that there is a similar war going on between aficionados of Photoshop and the GIMP. Photoshop is the best selling graphics package and the GIMP, or the Graphic Image Manipulation Programme is its leading open source rival. Luckily, I don't have to come down on one side or the other because as only the GIMP is free I only have to consider its merits in absolute terms. Photoshop may or may not be a much better option for the seeker after serious graphic gratification - I don't know because I have never had a go on it. What I can say is that for the ocaissional dabbler in graphics, the GIMP is very capable but does not make it easy for the novice to get the most out of it. I suspect that if you have a pretty good idea of what you are doing that it is a very useable piece of software. But its bewildering array of features and its very, how we shall we put it, original configuration don't lend themselves to its use for a quick bit of image tarting up. Pressing the wrong buttons can also get you into a frustrating cycle of futile clicking. Nonetheless the fact that it is free, that it supports a huge range of file types and that it almost certainly does actually do whatever it is you want to do justifies downloading it and devoting a modest bit of your hard disc to it. It comes in versions for Windows, Mac and Linux, and all are very similar to one another so it is a good choice for platform tarts or people who need to work on the same files at home and on a different system at work. I'll post a couple of step by step guides to how to do speficic things with the GIMP.

Friday 17 October 2008

Using Google Docs as a Blog Editor

Using Google Docs as a Blog Editor

If you are an enthusiastic blogger and a bit of a perfectionist, an off-line blog editor like Microsoft Live Writer or the truly awesome Ecto are well worth investigating. But if you just want to knock up a quick blog post, or you have an old document that you have decided you want to share on the web then it might be worth bearing in mind that you can use Google Docs as a rough and ready blog editor.

Write the post as you would any other, then save and close the document. Go to the main Docs window and tick the document. Pick the More Actions option and select publish.

If you haven't carried out this process before you need to go to the bottom of the page and fill in your blog settings - so you will need to remember your password. If you run more than one blog you need to make sure that it is set up for the blog you are working on.

Then just press post to blog and you are done.












Setting Up Joomla on your hard disc

Setting Up Joomla on your hard disc

You can download all the components you need to install and run Joomla on your hard disc. If you are au fait with computers and web hosting at a high level this is a straight forward job and should take less than an hour. However, if you have that level of skill you probably don't need to run Joomla straight off your hard disc, you can get on with creating great web applications etc. If like me you are a mere mortal who wants to give Joomla a try to see how it works, or if you already think it is something you want to get into but need a chance to get to grips with what it offers, then this is the guide for you. I started writing it in the middle of my first attempt at Joomla installation - more as a way of clearing my thoughts than anything else. I assume no knowledge of anything beyond what an average user of the internet might know. Believe me, I know very little more than that myself. There are a wealth of Joomla guides out there and I might well be duplicating something that someone else has done, but I could not find precisely the information that I needed to install Joomla myself without considerable trauma. I was at times driven to the blackest depths of despair while trying to set up my installation. If I can spare just one other person the almost suicidal frustration of staring at a screen without a clue as to why it isn't working or what to do next, then the work of creating this guide will have been worthwhile.

If you have the choice, I would strongly recommend installing Joomla using a Mac rather than a Windows PC. I started my first installation on Windows and hit several brick walls. It wasn't until I had a go using my Mac that I managed to fathom out how it all worked and to finally get it running on Windows. I realise that Windows is by far the more important platform so I am going to concentrate on instructions for getting going on Windows, but will add some notes for Mac users as well.

First a quick overview of what we are going to do.

1. Set up a server on your computer. This is a bit of software that creates a directory that you can use as a sort of virtual bit of the internet that you can set up your website on. The one we are going to use is Xampp.

2. We are going to install the Joomla files into a directory on your computer.

3. We are going to run through the set up procedure for Joomla.

4. We are going to set up a Joomla website that you can play on to learn the interface.

Every one of these stages is relatively straight forward but I had problems with every one of them when I was working out how to do it. I am going to give very strict and precise instructions that you must follow to the letter. I will explain what is going on, or at least what I THINK is going on after that.


Stage 1: Download and install Xampp

Xammp can be found at various places on the net, a Google search on Xampp Download will throw up plenty of options. I got it from http://www.apachefriends.org/en/xampp-windows.html. Chose the installer version. This is a self executing file. Once you have downloaded it you simply click on it to launch the set up programme. Close down any programmes that are running and click on the file. You will be prompted for four different services to be installed - Apache, MySQL, Fliezila FTP and SMPT. Chose the first three and press install.

The default installation directory is c:\xampp. Do not use this suggestion. Put it in your programme directory instead.

The installation is quite long, it could well take about 10 minutes
with a great many files being copied over and at one stage a black Dos
Terminal box will appear. Once it has finished there is a bit of an
anti-climax as nothing much seems to have happened.

In order to check that everything is in order you need to launch a browser. Either Internet Explorer or Firefox work well, and I imagine others would as well. You need to type the following web address into the browser bar, exactly as written, http://localhost/ . Cutting and pasting from here would be a good way to do it.

You should get a screen with the Xampp logo and a set of language options. Select the language you want to use and you get a page with lots of technical information about Xampp. None of this concerns us for now, we are ready to move onto the next stage.

Stage 2: Download and install Joomla

Joomla can be downloaded from the Joomla page, http://www.joomla.org/. While writing this guide the release number was 1.5.4. For Windows I chose the zip file version.

Once you have downloaded it you need to create a directory called Joomla in the htdocs subdirectory of your xampp installation. Unzip the contents of the Joomla zip file into this directory.

Now you need to install Joomla. The easiest way to do this is via a browser. Enter http://localhost/joomla into your browser bar and the installation page of Joomla will appear. Before you start, decided what you want to call your website and have an e-mail address handy. You are also going to be asked for a password.

Step 1 - enter the name of your database. Once you have filled this in you need to click on next in the top right hand corner of the screen. Personally, I find this an odd place to put it but that is the way it is.

Step 2- the pre-installation step checks that you have the right set up. If things are in order you will have a satisfying row of green yeses. It should all be okay, though you may find that the last one is red. If this is the case don't panic, this can be sorted out by hand later.

Step 3 - read and thoroughly understand all the details of the license agreement. Everybody always does this and if you skip over it with a quick glance you will be the only person who has done this.

Step 4- this actually sets up your database so take care to get it right.

Hostname = localhost
User Name = root
Password = leave blank
Database name=joomla


I suggest downloading the sample data. It is easier to get to grips with Joomla with an example to look at, though the sample data is quite a bit. You will have to do a lot of deleting later. If you have a very clear idea of the content you are going to be adding later you might want a clean installation, in which case don't press the sample data button.

Step 5 - skip this.

Step 6 - Enter the name of your website. This is the name as it will appear on screen so don't include the .com bit unless you want that to be displayed.

You now need to manually delete the installation directory (it is called installation so it is easy to find).

Once you have done this your Joomla website is up and running.

To look at it you type http://localhost/ joomla into your browser bar.

To work on it you type http://localhost/joomla/administrator into your browser bar.

A couple of points to remember. Xampp needs to be running for the process to work. On Windows the default is for it to load up automatically. On the Mac you will need to both run Xammp from the applications folder which means you need to put your password in, and you then need to actually run all the utilities.





Sunday 12 October 2008

Installing Wordpress on your Website

Installing Wordpress


Assuming you have already set up web hosting and have a domain name, this is how to set up your own blog using Wordpress.

Installing Wordpress really is a breeze, but I personally found the instructions on the Wordpress website just a little too sketchy and I also found the constant reassurances that it was easy a bit disconcerting when I ran into difficulties. The stages are:-

1. Download the latest version of Wordpress from http://wordpress.org/download/ .

2. Unzip it to a folder. Personally I like to do this sort of thing on my Desktop so I can find it again easily if I get into trouble and to remind me to get rid of all the superfluous files at a later date when everything is in order.

3. Use an FTP programme to transfer the contents of the folder you have just created to the htdocs folder of your web. A good FTP option is the FireFTP Firefox extension.

4. Set up a MySQL database. The service provider should have instructions on how to do this. Make a note on paper of the following.

MySQL Server e.g., MySQL14

MySQL Host Name e.g., 79.99.43.20

MySQL User name e.g., independen3

MySQL Password e.g., s146952

5. Use your FTP programme to find the file named wp-config-sample.php. This will be in the directory Htdocs. Rename it to wp-config.php (to do this in FireFTP click on it while holding the control key).

6. Edit the file (to this in FireFTP highlight the file and click on it while holding the control key). The contents of the file are:

<?php// * MySQL settings * //define(‘DBNAME’, ‘putyourdbnamehere’); // The name of the databasedefine(‘DBUSER’, ‘usernamehere’); // Your MySQL usernamedefine(‘DBPASSWORD’, ‘yourpasswordhere’); // …and passworddefine(‘DBHOST’, ‘localhost’); // 99% chance you won’t need to change this valuedefine(‘DBCHARSET’, ‘utf8’);define(‘DBCOLLATE’, ”);

// Change each KEY to a different unique phrase. You won’t have to remember the phrases later,// so make them long and complicated. You can visit http://api.wordpress.org/secret-key/1.1/// to get keys generated for you, or just make something up. Each key should have a different phrase.define(‘AUTHKEY’, ‘put your unique phrase here’); // Change this to a unique phrase.define(‘SECUREAUTHKEY’, ‘put your unique phrase here’); // Change this to a unique phrase.define(‘LOGGEDINKEY’, ‘put your unique phrase here’); // Change this to a unique phrase.

// You can have multiple installations in one database if you give each a unique prefix$table
prefix = ‘wp’; // Only numbers, letters, and underscores please!

// Change this to localize WordPress. A corresponding MO file for the// chosen language must be installed to wp-content/languages.// For example, install de.mo to wp-content/languages and set WPLANG to ‘de’// to enable German language support.define (‘WPLANG’, ”);

/* That’s all, stop editing! Happy blogging. */

if ( !defined(‘ABSPATH’) ) define(‘ABSPATH’, dirname(FILE) . ‘/’);require
once(ABSPATH . ‘wp-settings.php’);?>



Change it to

<?php// ** MySQL settings ** //define('DB_NAME', 'independen3'); // The name of the databasedefine('DB_USER', 'independen3'); // Your MySQL usernamedefine('DB_PASSWORD', 's146952'); // ...and passworddefine('DB_HOST', '79.99.43.20'); // 99% chance you won't need to change this valuedefine('DB_CHARSET', 'utf8');define('DB_COLLATE', '');
// Change each KEY to a different unique phrase. You won't have to remember the phrases later,// so make them long and complicated. You can visit http://api.wordpress.org/secret-key/1.1/// to get keys generated for you, or just make something up. Each key should have a different phrase.define('AUTH_KEY', 'put your unique phrase here'); // Change this to a unique phrase.define('SECURE_AUTH_KEY', 'put your unique phrase here'); // Change this to a unique phrase.define('LOGGED_IN_KEY', 'put your unique phrase here'); // Change this to a unique phrase.
// You can have multiple installations in one database if you give each a unique prefix$table_prefix = 'wp_'; // Only numbers, letters, and underscores please!
// Change this to localize WordPress. A corresponding MO file for the// chosen language must be installed to wp-content/languages.// For example, install de.mo to wp-content/languages and set WPLANG to 'de'// to enable German language support.define ('WPLANG', '');
/* That's all, stop editing! Happy blogging. */
if ( !defined('ABSPATH') ) define('ABSPATH', dirname(__FILE__) . '/');require_once(ABSPATH . 'wp-settings.php');?>
7. Now you need to run the installation programme by pointing your browser at the install file. You do this by entering http://yourwebsiteaddress/install in the browser bar. The installation programme will run and will generate a confusing admin password. You MUST write this down on paper. You will need it to administer your website.
There it is - your website is now up and running with the default Wordpress theme. This will probably look a bit familiar because there are a reasonable number of websites on the net that have never got beyond the stage you have just reached.

















FireFTP - A Firefox Extension FTP Programme

If you want to handle the files on your web-site you need to get to grips with a file transfer protocol or FTP programme. This used to be a bit of a black art and I have tried quite a few options before settling on this one. It is a Firefox extension so it runs directly from a browser and it is the one I have had least difficulty using.