All Posts on Web Development and Programming

Restart MySQL Ubuntu

We may want to restart our MySQL server for a number of reasons. The most likely reason for wanting to restart our MySQL database server is to load new configuration settings.

It is a good idea to ensure that no users will be accessing the database server when you are performing the restart just in case the restart fails.

Always backup your configuration files before making any changes, as fouled up configuration files are the most likely causes of a failed restart.

PHP md5 String and File Example

A hash function is useful for checking that something has not been changed. The md5 function is a popular hash function that can be used to generate a hash of a string of text or a file. A hash is useful since you cannot easily determine the input from the hash itself.

You may hash a file and send the hash with the file. The receiver can then rehash the file once they receive it to ensure that the file was not modified during transmission, since a modified file would generate a different hash.

Adding rel="nofollow" to Comments in Drupal 6

By default in Drupal 6, only the Homepage link of a commenter has a rel="nofollow" attribute attached to it. The commenter has free reign on all the other anchor tags inside the body of the actual comment. In many cases this is unsuitable especially for SEO purposes.

Spammers like to leave links in comments to transfer Pagerank from your page to theirs. By adding a rel="nofollow" attribute, no Pagerank will be passed to the external page and it will also serve as a deterrent to adding external links in the first place.

Disable Resizable Textarea Drupal 6

Drupal 6 allows textareas to be re-sizable and this may be a useful or annoying feature depending on how you look at it.

It may be useful since you are allowed to change the size on the fly to suit your needs and may be helpful when adding a lot of content at one time.

It may be a nuisance since an extra image (grippie.png) has to be loaded from the server to provide that functionality.

How soon after crawling do pages appear in Google's index?

Enthusiastic web publishers always want their new content to be found from a Google search as soon as possible. The short answer to the question of how soon can content appear in search results after being published is less than 24 hours.

Depending on how often Google (or other search engines) crawl your site, if you put new content on your site now, you can expect it to be in Google's index within 24 hours. It gets better.

Restart Apache2 Ubuntu

We need to restart our Apache2 web server when we want to load new configurations from the configuration files. Restarting the web server to load configuration files is necessary as these configuration files are only read each time when the web server is in the process starting.

Note that the Apache web server does not need to be restarted on every configuration change; sometimes a simple reload will do. In any case, restarting won't hurt.

To restart Apache2 on Ubuntu, we enter the following command in a terminal such as bash:

Add to Bookmarks Javascript for All Browsers

First of all, the title of this post is a bit misleading. No JavaScript code or any code for that matter can claim to add a bookmark in all browsers.

What we can say though, is that the code we present has been tested to work in all major browsers except Google Chrome.

Bookmarks come in handy when it comes to building visitor loyalty and getting visitors to come back to your site. The JavaScript code snippet we show in this article creates a simple hyperlink which, when clicked, requests that the browser add the current page to its list of bookmarks.

HTML Redirect

To perform a HTML redirect we need to make use of the meta refresh tag. This is a particular meta tag which is used to tell the browser to go to another location. Redirecting a browser using the meta refresh method is discouraged since an unexpected redirection may disorient users.

In some cases, redirecting a web page using the meta refresh is required. The method is suitable for periodically refreshing a dynamic page to get new news or status updates for example, and is used when Javascript methods of redirection are unwanted.

Ignore IP Address Awstats

In this tutorial, we will learn how to ignore or exclude specific IP addresses from our Awstats data. When set up, Awstats parses our server log files and generates detailed reports of user locations, IP addresses, referrers, and so on. Awstats can be used to give an excellent idea of where your visitors are coming from, how they got to your site, and what they are looking on once on your site.

Using this information will allow a webmaster to fine-tune aspects of his or her site for maximum user satisfaction.

How many pages should my website have?

Time and again we hear that "content is king" and that statement is very true. With that in mind, the question of how many pages a website should have often pops up.

If content really is king then ideally a website should have infinite pages.

That is for the perfect world, but in the real world you can get away with much less.

Change DNS Server in Ubuntu from the Command Line

Changing the existing Domain Name Server IP address or configuring DNS name resolution under Ubuntu Linux is fairly simple with the command line.

All you need to do is edit the /etc/resolv.conf file. You may want to change your nameserver for a number of reasons. Suppose your existing nameserver is slow or is not updating properly; you can specify a new nameserver to get rid of all those problems.

Simply use your favourite text editor to edit the file /etc/resolv.conf as the superuser.

To use nano text editor:

Using wget and an XML Sitemap to Spider website - Keeping the Drupal cache warm

This tutorial will speak in the context of using this technique on a website which uses Drupal for content management. This technique need not be limited to a Drupal website and should work well if adapted properly.

Drupal caching, when enabled, causes the system to store copies of generated pages to help the next request for the same page go faster. You specify the cache lifetime when setting up caching, and any pages in the cache which are older than the lifetime you specified are removed from the cache on the cron run.

Htaccess 301 Redirect

Redirecting a web page from one URL to another is best achieved using a HTTP redirect. You may want to perform a redirect after changing the URL of a page and you want existing links to the old URL to remain valid. In this tutorial, we look at how to do an htaccess 301 redirect.

Update Ubuntu using the Command line

Updating your Ubuntu Linux distribution using the command line is very simple two-step process. Using the package manager, you can easily update your system as it automatically finds newer versions of your installed software. To perform the update, you will need to:

  • Refresh the apt system to ensure it contains all the newest information about packages
  • Download then install any packages that have newer versions

Pretty simple isn't it? The details of updating are below.

Protect cron.php in Drupal 6

By default, anyone can run cron.php on a Drupal 6 installation. That means everyone with access to your website can run your cron.php file. Since cron.php is used for maintenance it would make sense that it is prevented from being run arbitrarily; whether or not an outsider running it can cause damage is merely a side issue.

What is Page RPM?

Page RPM literally means Page Revenue Per Thousand impressions. The letter "M" in the abbreviation is the Roman numeral which means one thousand (alternatively it can be "mille" which means thousand in Latin). Page RPM is basically a calculation which shows the average projected revenue of a page per thousand impressions that it gets.

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.

Check PHP version

We can check our PHP version in 2 major ways; via a PHP function and via the command line. 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.

PHP offers a useful function called phpversion which provides us with the current version of the PHP interpreter.

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

Get 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://';