The crisis of the storage space – part two.

Monday, February 10th, 2014

If your windows machine has run for twenty days straight without crashing or otherwise needing a restart, then congratulations!

It also means I should share with you a little secret. Windows uptime = disk space used for the page file, etc. A restart will significantly cut hard disk usage (4GB in my case :)) and allow you to continue working.

I would write more but I simply couldn’t be bothered. Believe it or not I have a life.

Using MySQL with PHP

Sunday, February 9th, 2014

Today I shall discuss a subject that took me ages to get my head around. It took me an incredibly long time to understand how to access SQL data within PHP.

Hence why I wish to make it easier for anyone else who is struggling to understand it.

To begin with you need a MySQL database (and a table to help speed things up). This post assumes you know how to do this for brevity’s sake. Now you need to access the database from within PHP:

This example is written in the procedural style. The object oriented style is written differently!

<?php
$db = new mysqli('server','user','password','database');

$people = $db->query("SELECT * FROM people WHERE gender='female'");
while($person = $people->fetch_assoc()) {
echo $person['name'].'<br />';
}

This code fetches all the names of people in the table 'people' who are female. Let me explain:

$db is how the script accesses the server. You can have more than one server instance. For example, I may have one accessing a database on an old server, to be moved to a database on a new server, or another database on the same server. new mysqli creates a new instance of server access. 'server' is the server address, which in most cases is either localhost or 127.0.0.1. 'user' is the username of a user who has permission to view the tables on the server. 'password' is obvious. It is the password of the aforementioned user. 'database' is the name of the database that this script uses.

I, for example may use
$db = new mysqli('localhost','ben','12345','friends');

Next is $people. This contains the query to be sent to the server to get all the records in the table 'people'. $db->query tells the server to query the database instance $db with the query to be mentioned next.

"SELECT * FROM people WHERE gender='female'" is the sql query. It is sent to the server to make it ‘do’ stuff. SELECT tells the database to fetch records from the server. ‘*’ tells the database to fetch all the columns, for example name, address, date of birth, gender, etc. FROM people tells the server to fetch all columns of information from the table called 'people'. WHERE gender='female' tells the server to fetch all columns of all records that match the WHERE clause, which in this case is records where the specified gender is female.

'while($person = $people->fetch_assoc())' Is the start of what PHP does with the data. $people is only a query, and it doesn’t contain any information. $person = $people->fetch_assoc() creates a new ‘person’ object which contains the data of the first record associated with the query contained in $people. You may have noticed that only the first record is selected, but the next records are selected when the while statement loops back, and so on until there are no more records left to process. Simple, right? ;)

After the while statement, there is then echo $person['name'].'<br />'; inside two curly braces. The curly braces define what code the while statement runs each time it loops. echo tells the script to print some stuff to the browser. Remember that the browser does not get to see any of this code, and so this line will be the first line sent to the browser. $person['name'] contains the content in the ‘name’ column of the record being currently processed. It can be changed to other names, such as $person['address'], $person['date_of_birth'], $person['gender'], etc. and it will echo different things. the dot in between the variable and <br /> tells the script to join something on. <br /> tells the browser to create a new line. Without this line, all the names would be printed in one long line.

The output of this could be:

Janet
Michelle
Emily
Susan

Changing the $person['name'] variable to $person['gender'] would be guaranteed to display:

female
female
female
female

This is because of the WHERE clause I wrote about earlier.

Of course, questions are welcome in the comments, which will be answered and included in this post!

The crisis of the storage space

Saturday, February 8th, 2014

I have run out of hard disk space on my computer.

I have run out of hard disk space on my other computer

I have run out of space on all of my external storage devices, including the SD and CF cards for my camera

I have run out of space on my current phone, my old phone and my school-tied iPad

I have even run out on my Raspberry Pis.

In case you haven’t noticed, I’m running a little short on storage space.

This isn’t the first time it has happened, and I doubt it will be the last, but I’m damn well sure that it is a problem.

So how does one go about solving it then? Well, I started by uninstalling everything I didn’t use, regardless of whether I needed it or not. I went on to remove old documents I didn’t need any more (which I really, really hate doing), before clearing out system temp files and removing update backups.

It is about this time I deem it ripe to rebuild a computer. This requires a backup of my documents, which, well, I can’t exactly do.

Oh dear sweet mother of all things holy in and out of the computer world.

In case you hadn’t noticed, I’m not feeling too good about this.

I will keep you updated.

With faithful regards,

Me.

Hardening WordPress plugins

Thursday, February 6th, 2014

I write code.

Yes, most of you know this, but what most of you don’t know is:

I didn’t write secure code, until now.

Let me explain: It is no good building a website for a client and going “Hey! Here’s a new site I’ve built you. It’s super secure!”, when you haven’t given one thought the people on the dark side (of the planet and of the force), and allowed for SQL injection attacks.

SQL injection attacks are where people ‘inject’ code into your site. Imagine this scenario:

A good person goes onto the website and enters ‘Josh’ into a box called ‘username’.

The PHP for this database query looks as so:

$age= $_POST['username'];
$db->query("SELECT name FROM people WHERE username='".$username."'");

This code inserts $username into the mysql query. The query that is sent to the database looks as follows:

SELECT name FROM people WHERE username='Josh';

So what happens if someone injects SQL into this query?

Say Mr Baddie comes along and enters Josh'; DELETE FROM people into the ‘username’ box, the query sent to the database will be:

SELECT name FROM people WHERE age='Josh'; DELETE FROM people;' Note the apostrophe at the end!

Or

SELECT name FROM people WHERE age='Josh';
DELETE FROM people;'

A lovely list of people with the username Josh will be returned. Before promptly deleting everything from the table ‘people’.

Oh Dear. I hope someone remembered to take a backup of that database.

Once people have been observed throwing insult-ridden shouts across the office at each other, blaming each other for the incident; and the boss has been to throw his own insults; and the site has been down for a week; and the head office has held a conference call to throw their own insults, it is finally time to sit down and work out what went wrong and how it can be prevented in the future.

Option 1: Delete the site and pretend none of this ever happened.

Option 2: Use different users for fetching and writing data to the database.

Option 3: ‘Sanitise’ the code to prevent SQL injection attacks.

I suggest Option 1 if you want a 100% guarantee that this will never happen again, but a compromise is required for those who don’t want to/can’t take it that far.

I suggest Option 2 & 3 for the near best you can get. I will explain Option 3 only.

The process of sanitisation not only protects against code injection, it also protects against the good guys potentially accidentally breaking your server.

There are different ways of sanitising user input for each language. I will demonstrate how to sanitise input for a mysql database through php.

It’s a function called mysqli_real_escape_string

So, instead of putting the given input straight into the sensitive belly of the database, I need to sanitise it.

Here’s the code instead.

$age = $db->real_escape_string($_POST['username']);
$db->query('SELECT name FROM people WHERE age=".$username');

So when Mr Baddie inputs Josh'; DELETE FROM people into the ‘username’ box, the content is sanitised and the day is saved.

The End.

Winter

Wednesday, February 5th, 2014

It’s cold and dreary outside – and since I’ve been home for an hour, and there is a cold cup of tea I made waiting downstairs because of it – It’s also dark.

It’s that miserable time of the year again.

Now, I won’t lie: I like rain. There’s something really nice about just walking on your own down a quiet street where it’s just you and the rain. Oh, and the umbrella. I always have my umbrella with me.

This is the time of year where everybody (myself included) gets a bit snuffly, and we go around as a staggered group of warriors, passing it on to anyone who hasn’t got it, because that’s just what we do.

I’d love to sit and continue writing, but I have some other work to attend to.

Please come back soon, and one hopes I will have written something good.

I’m sorry I haven’t posted for so long. A lot has happened since then. Happy Colorado day, Tisha B’av, Victory Day, Hawaii Statehood Day, Labor Day, Carl Garner Federal Lands Cleanup Day, National Grandparents Day, California Admission Day, Patriot Day, Constitution and Citizenship Day, Emancipation Day, September Equinox, Rosh Hashana, Native Americans’ Day, Gold Star Mothers Day, Feast of St Francis of Assisi, Yom Kippur, Eid al-Adha, Child Health Day, Sukkot, Leif Erikson Day, Columbus Day, White Can Safety Day, Shmini Atzeret, Boss’s Day, Alaska Day, Diwali, Muharram, Halloween, Nevada Day, All Saints’ Day, All Souls’ Day, End of Daylight Saving Time, Election Day, Return Day, Veterans Day, Thanksgiving, Presidents’ Day, Black Friday, American Indian Heritage Day, First Day of Advent, Cyber Monday (whoop, whoop!), St Nicholas’ Day, Pearl Harbour Remembrance Day, Feast of the Immaculate Conception, Feast of Our Lady of Guadalupe, Hanukkah, Pan Am Aviation Day, Wright Brothers Day, Christmas Eve, Christmas Day, Boxing Day, Kwanzaa, New Year’s Eve, New Year’s Day, Epiphany, Orthodox Christmas Day, Stephen Foster Memorial Day, Prophet’s Birthday, Orthodox New Year, Tu B’Shevat, Lee Jackson Day, Confederate Memorial Day, Martin Luther King Day, Idaho Human Rights Day, Civil Rights Day, Kansas Day, Chinese New Tear, National Freedom Day, Groundhog Day and Rosa Parks Day

I don’t know about you, but I think we have too many holidays.

The end of the PC is nigh.

Monday, July 1st, 2013

Firstly, I do apologise about the hideous colour scheme on the last theme, the green made me see yellow.

As one who browses the internet for hours upon hours a day, it didn’t take long to realise how much buzz there was a couple of years ago about ‘cloud computing’, and after kicking my feet up for those past years saying to myself ‘That’ll never happen’ – and before I knew it the world overtook me and I was bombarded with adverts for cloud hosting and it was all quite frustrating.

But since then, a new threat has cropped up. The tablet. A lightweight, easy to use and very portable system, which got me scratching my head. It didn’t have a keyboard.

Now I know I’m meant to be a ‘computer boffin’ or what have you, but I really couldn’t get my head around the idea that a computer is now this touch screen with a battery, a pretty solid mobile processor, a long -ish life battery and a hard casing on the back. It was like someone had decided that the laptop was too easy to break, and so they broke off the lid, and went ‘Hey, I could make money out of this idea!’.

Windows for Pen Computing kicked off Microsoft's tablet efforts back in 1991.

Windows for Pen Computing kicked off Microsoft’s tablet efforts back in 1992.

If I’m honest. I should have seen this coming. Tablets have sort of been around since before I was born. Take Windows for Pen Computing. It was an application that could be bought for Windows 3.1 (I know, right? 3.1 was like April ’92). It allowed 3.1 to be used on these primitive plastic tablets, which at the time, could run an Intel processor, but not for a day’s work.

Since WfPC Microsoft made a whole load more mistakes, right up to the point of a ‘touch screen table‘ in 2008. With no hardware or software developers, virtually no buyer market and the fact that they were only available after filing a request with Microsoft, and going through a screening process and having a swarm of checks made on you/your company, it was clear this product was not to make money, it was simply to prove that Microsoft knew what they were doing when it came to tablets. and they do, with the exception of hardware.

Microsoft have always done an amazing job when it comes to writing software, but they’ve always been a bit, well, crap when it comes to their hardware. Remember the snapped off lid I mentioned earlier? They took that a step further by allowing you to attach the keyboard back on. And take it off again.

I really shouldn’t be giving Microsoft Surface all this hate. It follows on an idea which Apple have dropped altogether. I said I don’t understand tablets, and it’s true. But what I do understand is the idea of Tablet PC’s.

My First Tablet PC - A Toshiba Portégé M200

My First Tablet PC – A Toshiba Portégé M200

I used to have a tablet PC, if I remember rightly it was a Toshiba Portégé M200-16M. Lightweight and rugged, with a screen which twisted round and locked down, it was a brilliant first laptop and tablet PC.

SIDE NOTE: I spent so many hours on that thing, I could swear the screen got a few millimetres thinner!

It is thanks to Microsoft that the Tablet PC is being dug out of its grave, with the release of Windows 8, everyone has been scrambling to get their lines of portable computers stocked up with tablet PC’s once more. The Microsoft Surface is to be disliked in my opinion, however it it designed to keep Microsoft revenues rolling in, because Microsoft and Bill Gates made their fortune on the Software, and with Entry Level Windows 7 Home Premium rolling off the shelves at £80, and the OS line going up to their top end Windows 7 Ultimate at £150, it’s no suprise that Windows needed a financial solution now that their Windows 8 lineup is cheap as dirt, and so came up with the idea of a tablet / tablet PC hybrid. Yes that’s right, tablet AND tablet PC, that’s the removable keyboard that stirs that one up.

Quite frankly the iPad is a disaster, and Apple have messed up their pricing, so they get a minimal mention in this post. Does this mean I’m a Microsoft kinda guy? I’m writing this from Windows 7, installed on a Mac. Hmm.

It’s now just a wait until the guys in Cupertino (Yes, that means Apple) come up with a comeback for the tablet PC hybrid.

So, to sum this up, Microsoft have been toying with this tablet idea for far longer than Apple have been even thinking about it, I used to have a laptop with a French name, Mobile devices are going to take over the world, and Windows 8 is pretty rubbish. Thank you for reading!

Ben Wilkinson

I can’t buy clothes.

Thursday, February 14th, 2013

Firstly, Happy New Year! Hope you guys all had good Christmases!

So I went shopping the other day, because my Dad decided that my clothes were getting too small for me. Well, he told me that they were too small, for about the fifteenth time, and my Mum had been fed up of buying clothes that then didn’t fit me when she got home, so we went into town together.

Now, I know what you’re all thinking: “Oh whatever, it’s not hard buying clothes, it’s too easy nowadays!” and I can see why you think that, but in actual fact you’re all wrong.

I’ve been having people constantly telling me that I’m skinny, and it’s true. I am skinny, but I’m also quite tall. This makes buying clothes (trousers, especially) quite hard. You can’t get trousers that are long enough but slim enough for me.

So I’m made to try on ‘skinny’ fit trousers – which is the wrong idea altogether; I really don’t like skinny fit trousers.

This means we have a real struggle with trousers. There’s only so much that a belt can do, and it usually ends up with great huge folds of fabric at the back of my trousers. Clearly this isn’t ideal, and causes problems.

So I’m having a moan on two things here: Trousers – which I have talked about, and Tops – which I haven’t.

Now, tops aren’t too hard to get in my size, although tend to be a little baggy because they aren’t designed for someone as skinny as me. Most of the time I’m alright with it, as long as it isn’t something like a shirt. Baggy shirts are worthy of either a charity shop, or a bin. Whichever is within closest reach – usually a bin in my case, although it hasn’t come to that yet.

So I really have just logged in to have a moan at the clothing companies. I know other people who have the same problem. They just see that the majority of people are short and fat, basically. It’s not true. To get clothes that fit properly, we need to get them tailored, which costs a small fortune, or hunt really hard – best done in summer, when it is warm.

So in the unlikely event that anyone from a major clothing company is reading this, please give us something to wear! Thanks

See you later, and don’t forget to have a look at the poll below!

Ben Wilkinson

10 years of Windows XP

Wednesday, February 6th, 2013

Hello all,

I hope you’ve all had a wonderful Christmas!

I received a new game, which just happened to not work with Windows 8. So I used Windows XP instead – which means installing all of the updates – bundled into service packs.

I soon realised that Microsoft has dropped support for much of Windows XP, meaning that I can’t grab the service packs and update the machine.

It was this that made me – like other people – furious, and I was about to actually write a letter of complaint to Microsoft (LIE), when it dawned on me…

Many of us have used Windows XP at some point. My old school had computers running Windows XP, and much of my new school’s library computers still run it. Everything else in the school is up-to-date-ish with the teachers using Windows Vista – the world’s worst OS in the history of mankind, and some machines run Windows 7. We don’t have any machines running Win8 yet.

So, we’ve pretty much all used Windows XP, and guess what? That shouldn’t surprise anyone, for the same reason that Windows XP support has been dropped: It’s now ten years old! (Happy Late Tenth Birthday XP!)

In my eyes, it is one of the best operating systems ever. In fact, I think it is the best. But there were always problems with XP, that aren’t now haunting us in Win7 and Win8. Most single user computers used the Administrator account as their standard account, which gave system-wide access to anything being run on the computer. Including any viruses, malware, spyware, worms, trojans, etc. installed on the computer. That is why – whilst still using XP as the standard OS for any Windows work I do – I only ever log into the Admin account to install software and update the machine, etc. Everything else is done on a ‘Limited’ Account.

Of course, you all know about the pesky Windows Updates that would give us a quarter of an hour to save up and let it shut down, and unless logged in as an Admin, you would be unable to postpone it. This gave me many problems, as I have the fancy logon screen, you know? The one where you have to enter a username and password, instead of just a click-me and enter password screen. Securer.

So, now that Microsoft is giving the techies like me a gentle nudge to move on from XP, by hiding the Service Packs from us when we want to install Windows, I am being politely held at gunpoint to move on. I do say politely.

Therefore, that means that the time has come to say goodbye to the OS that set itself in stone, because the stone is weathering away, and we need to go with the flow.

But since Windows 7 is rubbish, and Windows 8 is a pile of you-know-what, it’s time to switch to where I should be, after all, I am a mac user.

But Macs suck, most of the time.

It’s time… Hello Linux.

Screenshots of Windows 8 – Developer Preview

Wednesday, January 11th, 2012
Starting Windows 8 in Parallels Desktop

Starting Windows 8 in Parallels Desktop

Follow

Get every new post delivered to your Inbox.

Join 511 other followers