2009
06.09

As the tides start to rise and more and more people are jumping on there surf boards and heading to the land of Twitter, I ask myself the question “why?” and again “why?”. How does a site which comprises of the most tiny amount of coding possible, get so big? To be honest who knows exactly how they managed to do it, alot of people think its down to celebrities taking it under its wing and promoting it through use.

What is for certain though is it has become a viral internet phenomon in the last few months. Maybe its the querkyness of “twittering” in the rather sort of “sad” way. Or maybe its the less intrusive style of keeping up to date with what your friends, favourite celebs or favourite businesses / entertainment are up to.

In my opinion there is little to no comparison between the two sites in terms of useability and technical expertise expended in development. Facebook is by far the more powerful tool and has hugely developed since hatching from its first embryo years back.

Despite that these two large social networking sites look set to continually grow and are perhaps heading for a full on confrontation?

The other big question is, does twitter currently make much money? Yes it has alot of users, but how does it try to monetise the fact that it does. Amid reports google are interested in buying Twitter, however they have refused to speculate as at current twitter has little to no monetising on its site.

Who will win the war of the social networks? We will see in the coming months.

Twitter - Facebook | The Choice is yours!

2009
06.07

Up untill now I would have frowned at the possibility of this, yet over the last few weeks it has become apparent that infact running two domains off of the same ip address server which have very similar domain names and content can REALLY effect your google rank. I have always assumed that multi hosting is too common for google to base its crawling upon ip address rather than just simply using the domain name itself. However if your finding that your site should be ranking better or you have revamped an existing site using a different but similar domain name like us, yet the old one is now ranking better than before and your new one is ranking badly in the search engines keep reading!

The two domains we have in question here are www.streetcrime.cc which is coming up for 2 years old and www.street-crime.com which is relatively new - only 4 months old.

Both of these domains are hosted on the same server using a cloud hosting method, www.street-crime.com is significatly better seo’d than www.streetcrime.cc.

Stats According to Google and a few other tools

www.streetcrime.cc

  • External links (according to google webmaster): 220
  • Page Rank : 2
  • Alexa Rank: 539,638
  • Indexed pages in google: 73

www.street-crime.com

  • External links (according to google webmaster): 677
  • Page Rank: 2
  • Alexa Rank : 2,380,476
  • Indexed pages in google: 305

Google will crawl the content for both sites and will make some interesting calculations. In this case it has decided that the newer site www.street-crime.com is a subsite of the older domain name www.streetcrime.cc thus giving www.streetcrime.cc  all of the ranking benefits that www.street-crime.com has.

In this case it has boosted www.streetcrime.cc to number one for gangster game in google.com yet www.street-crime.com is no where to be seen.
This leads me to only one conclusion that hosting on the same server with very similar domains can effect your google ranking, in a bad way if you are trying to rank for both domains, like we are.

Solution

The simple solution would be to switch the domain names onto different ip address’s which is easily possible. This should sort the ranking of both of the domains out seperately then.

Any questions or help on how we got around this problem just leave a comment and ill get back to you.

2009
06.05

Input validation with javascript is an essential part of any large day to day website. Its major advantage is that it can be processed client side thus avoiding avoidable load on the server.
If your running a PHP based website which is struggling to cope with load and your using basic php form validation. You could switch your form validation to Javascript.

You should treat your javascript validation as your first line of defence, as javascript source can be read by a user its easy enough to work around it if you know what your doing. So you will still need to keep your second line of defence ie your PHP code to do the second lot of checking.

However the javascript will help to limit load for people who genuinely make honest mistakes.

Heres a example of form validation.

Firstly lets make our Form

[sourcecode='html']

Whats your name:   

[/sourcecode]

This will simply check to make sure they have not tried to submit the form without entering anyting in the input box.

This is a very very simple version of a javascript validation.

[sourcecode='javascript']

[/sourcecode]

Here we have added another line of validation to check to see they at dont try and just put one character in the box using javascripts .length function.

I will add some more to this post later, including email validation and more.

2009
06.04

I recently went on a football tour with my football club to the lovely city of Amsterdam and contrary to what you might think, theres alot more to the city than “coffeeshops” and the red light district haha.

Well for a starters we all know “coffeeshops” in the city of Amsterdam are not really coffee shops, they sell Hash and Weed and yes it is 100% legal. There wont be sneeky policeman hiding round the corner just waiting for you to hand over your money and collect the goods!  These can be taken in an assortment of un-luxurious / un-flattering ways, either by eating a hash cake, smoking a spliff or………well eating just about anything else with the drug sprinkled on top.

For the Amsterdam virgin this can be a real blast! However believe me when I say smoking or eating yourself into a coma all day is’nt quite the best way to spend your time in Amsterdam. If you reach the coma stage you’ll know what im talking about ;) when I say “you wont be doing that again for a few months or years depending on your experience haha!”.

With the Euro becoming stronger against the pound, your unlikely to pick up any bargains in Amsterdam, infact your actually likely to be paying more for a pint than you would back home in the Great Britania. Shots and spirits unfortunately are no better! The average was € 4.50 but paid anything up to €6.50 in some bars at night. Id suggest finding somewhere that does some decent drink deals early on and watering yourself to hell there moving on, and just topping up everywhere else.

Moving onto the things you should definitely check out in Amsterdam.

1. Drink Up

With more than 1200 different pubs to crawl you’ll have more than your fill.

Start at the Heineken brewery (Stadshouderkade 78) to see how famous beer is produced. Check out Café Belgique to taste smooth Belgian brews like La Chouffe and La Trappe Dubbel.

Other standouts:  In De Wildeman, Suzies Bar for you english people .

2. Night Bike it Up

One thing youll notice when you get to Amsterdam is EVERYONE is push bike NUTS! Its incredible there are even multi storey car parks for bikes. This in mind theres plenty of places to rent yourself one for a day or so.

Amsterdam is most romantic at night, when the city is aglow from lit up bridges and canals.

Start at Leidseplein and bike down Kerkstraat to the Amstel River, where you’ll find the Skinny Bridge in all its glory.

3. Club it Up

Clubbing in Amsterdam has a reputation for being very good, however only IF you can find them! Amongst all the bars and copius coffee shops it can sometimes be quite hard to come accross a club.

For pre-partying, head to Lux (Marnixstraat 403) Bitterzoet (Spuistraat 2), or Seymour Likely (Nieuwezijds Voorburgwal 250) for live DJs.

Join the dance crowd at Mazzo (Rozengracht 114), Club More (Rozengracht 133), and Paradiso (Weteringschans 6-8). For a laid-back vibe, check out Café Alto (Korte Leidsedwarsstraat 115) for local jazz acts.

4. Shop it Up

Walk the famous 9 streets (theninestreets.com), to pick up cutting edge fashion and eclectic wares.

Don’t miss Lady Day, which sells vintage and secondhand European fashion for a steal. Browse for a designer fragrance like Creed at Skins Cosmetics, investigate the Paul Frank Store , and get pampered at Spoiled, where you’ll be custom matched to a designer pair of jeans.

5. Do it Dutch

Nothing says typically Dutch better than a hunk of ‘Gouda’ stuffed in a fresh bread roll.

Savor this ritual by picking up a sandwich at Broodje van Kootje (Spui 28).

For another Dutch favorite, visit the Pannekoekenhuis, a tiny upstairs restaurant on the second floor of a narrow canal house. Dive into big pancakes, served sweet or savory.

6. CoffeeShops Not to Miss

At Café Zeezicht (Hoofdweg 456), people watch on the outdoor terrace, sipping a Dutch style latte and nibbling on the best apple tart in town. Brown cafes, named for their wooden interiors, are good for mingling with the locals.

You should pay a visit to the famous Grasshopper coffeeshop as well which has an outdoor terrace on the canal, and serves everything you can imagine a good old fashion amsterdam coffee shop should.

Cafes not to miss: De Balie, Café De Tuin (Tweede Tuindwarsstraat 13), and Café ‘t Smalle (Egelantiersgracht 12).

7. To The Market

Start at the eastern end of the Albert Cuyp street market in the ethnically diverse neighborhood De Pijp.

Peruse Dutch treats like fish, cheese, and chocolate among 300 stalls. Take a right on Ferdinand Bolstraat, then a left on Stadshouderkade.

Take a right at Spiegelgracht for a stroll in the antique district. Turn left onto Herengracht to see splendid 17th century canal houses. Make a right at Leidsestraat and go up to Singel.

Hit the Singel lunch Café (Singel 404) for homemade soups and baguette sandwiches.

8. Relish In Art

From Spui take tram 2 or 5 to Museumplein, where the Van Gogh and Rijksmuseum keep you occupied for hours.

View Van Gogh’s life through art, from the Potato Eaters up through the last two months of his life in France.

Holland’s Golden Age is the highlight of the Rijksmuseum. Don’t miss Vermeer’s Milkmaid.

9. The Red Light District

Contraversial I might hear you say! Entirely down to taste but eye opening none the less, plus always teaming with life. If your an avid fan, the going rate according to some contacts I will not name………is 50 euros.

10. The Dam Square

Pretty much the central of Amsterdam and an old square. Much of the cities life is in around the small streets leading off of it so its not to be missed! Watch out for trams and mad cyclists though!

2009
06.04

For quite a long time now ive been seeing lots of image upload scripts which boast to be able to upload multiple images at a time! 90% dont work.

So heres one I created and I know works. Firstly the below code is the functions to handle the images,  you do not need to touch anything here, just make sure its on your page.

[sourcecode='php']

//Dave Hewards image script

function resize($img, $thumb_width, $newfilename)
{
$max_width=$thumb_width;

//Check if GD extension is loaded
if (!extension_loaded(’gd’) && !extension_loaded(’gd2′))
{
trigger_error(”GD is not loaded”, E_USER_WARNING);
return false;
}

//Get Image size info
list($width_orig, $height_orig, $image_type) = getimagesize($img);

switch ($image_type)
{
case 1: $im = imagecreatefromgif($img); break;
case 2: $im = imagecreatefromjpeg($img);  break;
case 3: $im = imagecreatefrompng($img); break;
default:  trigger_error(’Unsupported filetype!’, E_USER_WARNING);  break;
}

/*** calculate the aspect ratio ***/
$aspect_ratio = (float) $height_orig / $width_orig;

/*** calculate the thumbnail width based on the height ***/
$thumb_height = round($thumb_width * $aspect_ratio);

while($thumb_height>$max_width)
{
$thumb_width-=10;
$thumb_height = round($thumb_width * $aspect_ratio);
}

$newImg = imagecreatetruecolor($thumb_width, $thumb_height);

/* Check if this image is PNG or GIF, then set if Transparent*/
if(($image_type == 1) OR ($image_type==3))
{
imagealphablending($newImg, false);
imagesavealpha($newImg,true);
$transparent = imagecolorallocatealpha($newImg, 255, 255, 255, 127);
imagefilledrectangle($newImg, 0, 0, $thumb_width, $thumb_height, $transparent);
}
imagecopyresampled($newImg, $im, 0, 0, 0, 0, $thumb_width, $thumb_height, $width_orig, $height_orig);

//Generate the file, and rename it to $newfilename
switch ($image_type)
{
case 1: imagegif($newImg,$newfilename); break;
case 2: imagejpeg($newImg,$newfilename);  break;
case 3: imagepng($newImg,$newfilename); break;
default:  trigger_error(’Failed resize image!’, E_USER_WARNING);  break;
}

return $newfilename;
}
[/sourcecode]

The next part is the important part which you will need to change some variables on to customise them for your own site.

[sourcecode='php']

//This stuff is outside of the function. It operates with our images
if(isset($_POST['submitimages'])){
$success=0;
$imgNumb=1; //This the “pointer” to images
$DestinationDir=”/sites/mysite.com/http/uploads/profiles/full/”;  //Place the destination dir here
$ThumbDir=”/sites/mysite.com/http/uploads/profiles/thumbs/”;  //Place the thumb dir here

do{
if($_FILES["img$imgNumb"][tmp_name]!=”){
$success++;
$Unique=microtime(); // We want unique names, right?
$destination=$DestinationDir.md5($Unique).”.jpg”;
$thumb=$ThumbDir.md5($Unique).”.jpg”;

$IMG=getimagesize($_FILES["img$imgNumb"][tmp_name]);
$finalimage = resize($_FILES["img$imgNumb"][tmp_name], 199, $destination);
//use the filename variable below to record the image name entered so that you can then use this variable to update your database if

$filename = md5($Unique).”.jpg”;

$field = ‘img’.$imgNumb;

//mysql update your database fields

mysql_query(”update profile set $field = ‘$filename’ where playerid=’$id’”);

}

$imgNumb++;
} while($_FILES["img$imgNumb"][name]);

if($success>=1){
$message = “Images uploaded!”;

}
}

[/sourcecode]

Finally you will need a little bit of HTML code for your form for the user to submit his/her new images to the site.

[sourcecode='html']

Change Profile Images:
Image 1:
Image 2:
Image 3:

[/sourcecode]

This code is tried and tested and it works so please enjoy and comment if you have some suggestions for ways to improve it further.

2009
06.04

To keep the browser from executing a script when the page loads, you can put your script into a function.
A function will be executed by a call to the function.
You may call a function from anywhere within a page.

Create a PHP Function

A function will only be executed when a subsidiary piece of code calls it.
[sourcecode='php']
function functionName()
{
code to be executed;
}
[/sourcecode]

Start by giving your function a name so in this case i will call my new function…findme();

[sourcecode='php']
function findme(){
echo ‘i found you’;
}
findme();
[/sourcecode]

As you will see from testing this my call to the function underneath it will make the browser execute the code inside the function echoing i found you onto the page.

Passing parameters to the function

Okay so we now have our findme() function which as it stands just echos something onto the page. This brings us to the two fundamental reasons for using functions. Firstly because they stop the use of repetitive code, if you needed to do the same 10 line or piece of code very often then you would save yourself alot of time by using a function to do so.

Functions are standalone so if you want the function to receive some kind of input so lets say for instance you have a form and you want to test what name was entered by the user.

[sourcecode='php']

function findme($name){

if($name==’fred’){ echo ‘dave’;}elseif($name==’Bungle’){echo ‘Sesame’;}

}

if(isset($_POST['submit'])){

$name = $_POST['name'];

findme($name);

}

[/sourcecode]

The function will now check the inputted name from the form in the function.

Returning Values From A Function

So at the moment our function will echo what it finds, but what if we want it to just pass a variable out of the function back to us? Well you simply use the return php function.

[sourcecode='php']

function findme($name){

if($name==’fred’){ $nam = ‘dave’;}elseif($name==’Bungle’){$nam = ‘Sesame’;}

//$nam now contains the variable that we want our function to return so simply just do

return $nam;

}

if(isset($_POST['name'])){

$nam = findme($_POST['name']);

}

//and thats it, now your $nam variable in your main php script will contain one of the names from above, providing someone enters one of the names i used in this example.

[/sourcecode]

This is the very basics of using and creating a php function! Check my other articles coming soon for more in depth articles!