Web Development Tutorials for January 2011

MySQL Array to PHP Array

We saw in our MySQL Fetch Array Tutorial how to retrieve data from a MySQL database using PHP. This post is similar but will focus on converting the array that is returned from MySQL to a PHP array.

This technique is important as it allows us to convert data to a format that we can directly work on using PHP.

For the following examples, once again, we will assume that we have a database called "employees" and it contains an "employees" table as follows:

How often is Pagerank updated?

Pagerank, as we should come to know by now, is a measure of how authoritative a search engine determines a web page to be. Pagerank is usually on a scale of 0 to 10 with 10 being the highest.

Google provides a way for regular users to see the Pagerank of a page when using the Google toolbar. As we can imagine, the Pagerank (or any other statistical data from Google) shown will be somewhat out of date due to the sheer volume of traffic and processing that needs to be done on the data.

Get current PHP version

Sometimes we might want to know the current version of PHP that we are running. PHP offers a useful function called phpversion which does just that.

The version of PHP which we are using is sometimes important as some scripts rely on functions that are only available in some versions. It is a good idea then to check the version of PHP before using these scripts.

To get the current PHP version, we can use the code below or edit it as necessary:


PHP URL - Getting the current URL using PHP

If you want to get the current page URL (the one that is shown in the browser address bar), you only need a few lines of PHP code. You may want the current page URL in order to use it to build a link back to the current page or some other task like that.

The simple example below shows how you can retrieve the current page URL using PHP. This example assumes that the page is using the HTTP protocol and not the HTTPS protocol. The majority of the time this will be sufficient.

function getPageURL()
    $pageURL = 'http://';

Disable PHP Functions Using disable_functions in php.ini

PHP is a feature rich scripting language, but when used improperly, whether intentionally or unintentionally, it can cause damage to be done. This damage can be total compromise of the web server and/or its data. Using the php.ini file, we can easily disable PHP functions which we deem to be dangerous.

Website Critical Mass - An analysis of social networks and content driven websites

The definition of critical mass may vary widely but the concept remains the same. It is a quantity of something that above which will cause a chain reaction.

How does this tie in with websites? What drives websites first and foremost are its visitors. When we think of the critical mass of a website we are thinking about how many active visitors the website needs to have a chain reaction. Chain reaction in this sense will describe drawing the attention of more visitors to the site.

Htaccess 301 redirect to www

For SEO purposes it is a good idea to use a single form of your domain for accessing your website. That is, you should not have your site being accessible via www.example.com as well as example.com.

Doing otherwise will cause all pages of your website to have duplicates as search engines will determine www.example.com and example.com to be different sites, and rightfully so, as the domains are very different. Duplicate content is usually penalised heavily by search engines so it is a good idea to use the configuration below to solve the problem.

Redirecting index page to Directory Root using Apache

Sometimes, due to inconsistent linking, a link my be made to your homepage as http://www.tutorialarena.com/ or it may be linked as http://www.tutorialarena.com/index.php

Usually, both these pages are the same thing as index.php is usually configured in Apache as the page to be displayed when a directory is requested.

PHP isset vs empty

Persons often wonder what the difference between the isset function and the empty function in PHP is. Today, we will be looking at the 2 functions head to head by putting PHP isset vs empty.

Simply enough, the isset function checks to see if a variable is actually set and that its value is NOT NULL

Look at this example:

// variable is not set at the moment
if (isset($some_variable))
	echo "It is set<br />";

Drupal - Why Can't I Edit a Node That I Have Permission to Edit?

Sometimes when you add the appropriate permissions for a user to be able to edit a node you are surprised when no edit tab comes up and if you navigate to the edit URL directly you get "access denied". If you have added the permissions correctly and cleared all the relevant caches, the following may help you solve your problem.

Ubuntu 10.x - Hide Apache and PHP Version and Signatures

By default, your Apache web server (and PHP if it is installed) will indicate to clients the exact version of the Apache software which is running. This version information can be seen in the HTTP response header.

New Website SEO - The chicken or the egg

New website owners are put in a tight corner when it comes to promoting their new website. Modern search engines usually place higher rankings on those sites that have more sites linking to them. How then, is it that a new website will get anyone linking to it, when no one knows that it even exists since it is at the bottom of a search engine result page? The is the heart of the chicken and egg dilemma that new webmasters are faced with.