Saturday, December 27, 2014

Alternative ways to use PHP scripts.

Over the past 10 years I have used PHP quite extensively in my websites. Mostly I use php as a way to build each page pulling in files from around my server organising them and then displaying the finished result. It has worked very well most of the time.

There is a downside that I have noticed the more people visit my websites. The trouble revolves around the server hosting company where I host my websites. Occasionally the php will stop working, effectively leaving my website with blank or error pages. While the php scripts stop working the pure html pages that are stored on the server are still visible to visitors. Of course I could just create the html text files by hand and that would make sure this particular error doesn`t occur anymore, however with over 200000 pages to remake it is an impossible task. Impossible except of course I can use php to generate my webpages and store them as pure text files.

Usually a webpage made using php would look something like this in code

The below file would be saved onto your server with a name like helloworld.php



echo is the most basic/easy way of printing text to the browser window.

helloworld.php

An alternative way to use the php script would be to do something like this. I`ll save this as generatepage.php on my server.



generatepage.php
helloworld.html

So what we are doing here is making a string variable $str and we are assigning it with the same information as the helloworld.php program but this time we are saving it using the fopen, fwrite and fclose instructions to a file called helloworld.html Okay so you might be thinking that is just making one file to make another and that is true but the real power in this method is that I can create one php file that could generate millions of pages from hundreds of files.

When we are trying to make a website one of the aspects we want to replicate each page is the title bar, layout and page ending (faq links, about links).

This is quite easy by using either includes or file_get_contents

Save a file called mywebsitetitle.txt with the contents



and we shall save the following in the file generatepage2.php



generatepage2.php
helloworld2.html

And for the final example lets make a slightly more complex file that will generate multiple files. First lets make a list of files that we want to create minus the ending .html. We will call this mywebsitefiles.txt and will look like this

Now we will update our page generator to load this file and for each filename go through the same process effectively creating 3 new files with the same layout and title bar. We will call the generator generatepage3.php and it looks like this. generatepage3.php

mywebsiteindex.html
mywebsitefaq.html
mywebsiteaboutus.html

The key is the foreach loop which allows us run the same instructions many times. We can add titles, meta tags, descriptions, text files and images to create differenet pages but with the same layout we makes for a good user experience.

I hope this has been of use to you and if you have any questions don`t hesitate to ask!

Thursday, December 11, 2014

How to Build To Withstand the Weather

My wife is a Filipina. Most of her family live in and around Cebu and Leyte. You might remember Leyte from Typhoon Haiyan last year that killed over 10000 Filipinos. A sad day for sure.

My wife didn't have direct relations living there but she did have friends who lost loved ones.

The Philippines gets at least 20 typhoons a year not to mention earthquakes, floods, and many other natural occurances. I keep thinking about our future and wanting to live in Cebu but the natural disasters there are certainly something I have to consider.

I look at the types of buildings available from nipa huts which are just wooden houses on stilts to the more regular style of breeze block buildings with wooden upper floors. Most of the houses are built as cheaply as possible due to the low wages and cost of materials. One thing always hits me, there are no round/cylindrical buildings. When you think of modern house building in fact virtually nowhere in the world will you find round house styles which is strange really.

The round shape gives a much stronger design while costing on average only 88% of material costs. If you imagine a force pushing against a round wall the force doesn't act on one point but is partly transfered around the whole wall making it able to withstand impacts better than a flat face.


Admittedly a round house needs a slightly wider land to achieve the same area for example a 10 metre by 10 metre house gives 100 square metres of floor space where as an 11.283 metre diameter round house gives the same area and with land at a premium this is out of the question for many Filipinos however not for me. I would prefer more land and build for less.

There are other bonuses to building round houses such as the shape which allows water and wind to flow around it instead of meeting resitance on flat faced dwellings.



The wind is also is less likely to try to lift the roof on a round house as the shape naturally means wind pushes the roof downward.

The more I think about the idea the more I am certain I will be building this style of house. Two floors with a central concrete column that will be used to support the roof and also replace load bearing walls. I can have curved balconies and a spiral staircase.

The best part of course is the ability to withstand all the types of weather that the Philippines can throw at me.

Thursday, November 6, 2014

How to fix a Hotpoint Washing Machine with Flashing Lights

A little while ago my wife mentioned that our hotpoint washing machine was having problems. Its a WF541 model.

As I turned the machine on the 5 lights indicating the steps in the wash cycle began flashing on and off at intervals of around 1/2 a second. My first instinct was a problem in the power supply. The control panel in most washing machines has a few components to regulate the supply. Capacitors, thyristors etc...

My first step was to remove the control panel from its housing at the back of the washing machine. This particular model has a metal panel at the rear of the machine at the base. Make sure to unattach the water supply, the electric plug from the wall and keep the waste pipe high. Now take out the screws from the panel and keep them safe. As you look at the rear of the washing machine the control panel is on the far left of the unit. It is housed in a white plastic container with cables attached. The best thing to do before stripping the plastic box down is photograph the box with the cables attached so that you know how to re-attach them later.

Once open I started to scan the circuit board for solder that had cracked, corrosion and the general appearance of the components. It was soon obvious what was causing the incorrect operation. You'll notice in the next picture the 4 cyclinder shaped capacitors. Can you see that the second largest capacitor (the brown one) seems to be dome shaped on the top? That is a failing capacitor.


This particular capacitor is a dielectric 680 micro Farad 10 volt. They are quite difficult to buy so I used a 1000 micro Farad 16 volt capacitor instead. Make sure you get the capacitor the right way round. All dielectric capacitors have a negative side that is displayed as a white or silver bar running down the side. Once I had finished reconnecting the control panel, replaced the metal panel and attached the water and electricity the moment of truth!

Everything worked beautifully. Trust me I'm an electronic engineer.

Friday, October 24, 2014

Had to Replace My Power Shower Last Night.

I found myself in a rather unfortunate position last night of being naked below a shower that would refuse to start. Its one of those power shower units. It pulls the hot and cold water through by a motor. It had been threatening to die on me for a while so it was a good thing I had a replacement safely stored away in my garage for a not so rainy time. See what I did there?

The original unit was 15 years old. Not bad for an often used item. My replacement while not the exact same model was from the same manufacturer. Triton. It turned out to be an excellent choice.

I had to quickly locate the stop valves for the hot and cold water. The hot was in my airing cupboard and the cold in my attic. Whoever installed the original didn't have the concept of future proof in his head. Even worse, the power was attached onto the lighting ring main. Now 7 o'clock in the evening in autumn is pretty dark around here. Time for torches and candles while I sorted out the unit.

My kids were unfortunately trying to get to sleep while I made all the noise but I guess they see it as a bonus getting to stay awake late.

I disconnected the wiring and then screws attaching the shower unit on the wall. I had to physically pull the unit away from the water pipes to disconnect them and it turn out there was quite a lot of water in the pipes. So much so that I think the stop valves probably weren't working very well. At least the water was just running into my bath.

The new unit was then pushed onto the pipes and this is why it was such a great choice to buy from the same manufacturer, I didn't even had to drill new holes in the wall. Everything went back where it came from. Same screw positions, same shower hose. I quickly re-attached the wiring, put the cover on, checked everything over and then turned on the water and powered up the system. It spluttered a little, I guess as it has been sat in my garage for about 4 months. I think the brushes on the motor had rusted slightly from not being used. I was just in the process of turning it on and off for testing and to see why it was spluttering when I forgot the shower head was on the floor pointing up at me. A quick dry down and I was ready to give a full test. Cold temperature. Check! Hot temperature Check! Fast and slow speed check!

Not bad I think. Fully installed in around 30 minutes. Then it was time to get naked again. What a refreshing shower it was too. Stronger than the last unit as well. Bonus!

Saturday, June 28, 2014

The Growth Of Opera Mini Is Hurting My Revenue From Adsense

Opera Mini is an excellent browser for people with limited bandwidth allowance on their phones. I have been using it for perhaps 5 years. Unfortunately for me it has a downside and that is that Opera Mini doesn't display my adsnse units. It is a policy of Opera Inc to strip out what it thinks is unnecessary code from a webpage in order to make the data smaller for the Opera Mini browser.

Peculiar thing is it leaves adverts from many other advertising companies.

2 years ago around 7000 people visiting my website were using Opera Mini, but that has now grown to over 16000 a month. The downside to this increase is that my numbers haven't increased so the opera users have directly replaced visitors that would have seen adverts. With an estimated 1.7 pageviews per visitor I am losing revenue from an extra (16000-7000)*1.7 pageviews each month than 2 years ago. It leads to hundreds of pounds of lost revenue!

My hope is that as mobile operators start to offer more and more bandwidth for less money each month the need for Opera Mini will disappear. At that point I will finally maximise the full potential of my website.

Monday, June 23, 2014

Effect of World Currencies On Adsense Earnings

Over the last 1 and 1/2 years I have noticed a decline in my adsense earnings of around 30%. Now I'm not one of those to instantly blame panda, penguin or any other types of update from google. I much prefer to work out why things change and what if anything I can do to rectify that 30% drop.

Firstly the bad news, it isn't possible to rectify the drop in earnings without increasing the number of visitors. Why isn't it possible? Because the British Pound has strengthened against virtually every currancy in the world including the Dollar, which has adversely affected my earnings.

Most of my visitors are from Indonesia, Japan, the USA and the Philippines, with 1/3 of overall earnings specifically from Indonesia. In 1 and 1/2 years the pound has changed against the Indonesian Rupiah from roughly 14500 rupiah to the pound to 20400 rupiah to the pound. A huge change that directly affects my earnings. The problem is that the average price per cpc advert an Indonesian company has to pay hasn't increased inline with the exchange rate.

Now lets look at the Pound to Japanese Yen. At the beginning of 2012 one pound was worth roughly 138 yen, it is now closer to 170 yen. Not quite as bad as the rupiah but still around a 23% drop.

My long term forcast is that within 5 years the currency market will start moving back in my favour. Until then, on with the day job.

Monday, April 16, 2012

How To Get Contextual Ads to Display on Your Webpages

Over the last few months I have noticed that more and more of the adverts that adsense has been serving me have become irrelevant to the content on the pages. I suppose this is my fault really for not fully understanding how to tell the google ad servers what my webpages are about.

This has originated from when I first started my website over 7 years ago. Before you start to say "Why didn`t you see it sooner" I just want to say that until recently the website has been more of a hobby than a necessity. In the present economic climate the revenue I get from my website is crucial to hold my head above the water instead of drown in the ocean like many other web publishers.

For my website, it is harder to make google realise what a webpage is about as my whole website is regarding language translation. Only 1/13 is in English with the rest being chinese, german, french etc... etc...

I`ve been looking over google analytics for a long time and the depth of the statistics can be dumbfounding but I`m starting to realise which pages perform badly for adsense and the reason why. The adverts have nothing to do with the content.

Most people know that you can guide google in the right direction with google_ad_section_start and google_ad_section_end inside the web content but this has never worked for me. Then I started to play around with the meta description and meta keywords in the header and wham! I have always had description and keyword meta tags but now I know they were no where near complete. As my website is in PHP I have always self generated those two segments of the webpages as it makes it easier handling the different languages but it was a big mistake.

Now I have started to go through my whole website and adding really focused keywords and descriptions that are 2to 3 times the size and this has started to see a change in the tide of adverts being shown. Irrelevant Ads will be a thing of the past, but for now I still have a few thousand pages to adjust.