Web Development Tutorials for May 2011

How to change file permissions in PHP

In this tutorial, we will look at how to change file permissions in PHP. File permissions specify to what extent users are allowed to interact with a file. These interactions are usually reading the file, writing to the file, and executing the file. Users may also be denied all access to a file.

The PHP chmod function is used to change the permissions of a file. It's syntax is given below:

chmod ($filename, $permissions);

What is XFBML?

XFBML is eXtended FaceBook Markup Language. This is a markup language which allows a web developer to integrate Facebook functions into their website. XFBML works together with the Facebook Javascript SDK.

XFBML is a markup language just like HTML. This language has special tags which are different from regular HTML tags. In order for the browser to be able to process these new tags, the Facebook Javascript SDK which we mentioned earlier is used.

Access associative array from inside double-quotes in PHP

Outputting a variable as part of a string in PHP using double-quotes is straightforward. We all know that when strings are placed in double-quotes, the PHP interpreter examines them to see if there are any variables inside which we intend to output.

This is a very useful feature as it saves us from having to concatenate the variable to the string as in some other languages.

For example, this is how we would normally output a variable as part of a string in PHP:

$name = 'Sally';
echo "I love $name";

The result would be:

Disable user login to SSH

In this tutorial, you will learn how to disable user logins via SSH. By default on newer Ubuntu systems and some other Linuxes with SSH installed, all users who have an account on the system are permitted to login via SSH. This is undesirable in certain situations.

Use htaccess to Block IP Address

In this tutorial we will show how to use an .htaccess file to block an IP address. This is one of several methods of blocking incoming requests to a web server. Other methods include blocking the IP address at the firewall or in PHP code, etc.

There are many reasons why you would want to block an IP address. It may be someone or something wasting or stealing your resources by making multiple requests to files on your server. It could be someone trying to spam your site. Whatever the reason for wanting to block an IP address, the htaccess file comes to the rescue.

Backup Website and Email Encrypted Backup using a shell script on Ubuntu/Linux

In this tutorial, we will show you how to backup a website and then encrypt the backup before emailing it using only a shell script. This guide is for those who are running their web server on Ubuntu or another version of Linux. This is very useful as a website can be backed up automatically using cron, encrypted for protection, and emailed to a safe place.

Bash For Loop

The Bash for loop is useful when we want to repeat some instructions a specified amount of times. Loops are considered iterative commands as they perform iterations, also known as repetitions. For example, if we want to run a particular command 5 times, we would specify the command inside of a for loop and then tell the loop to run 5 times.

There are 3 major syntaxes for the Bash for loop. Note that not all variants of the for loop are supported in older versions of Bash. All 3 variants we show below are supported in at least Bash version 4.

Get Bash Version

If you are wondering what version of Bash am I using, then you have come to the right place. There are a number of reasons why one would want to know their Bash version. The most likely reason is compatibility. Even though the commands remain the same for the most part, different versions of Bash may add different features and functionality that may not be available in older versions.

Bash If Statement

The Bash if statement is similar to the regular if statements we take for granted in other programming languages. It allows us to take an action depending on a particular condition such as the value of a variable, user input, or the success or failure of a command.

As we begin to write more advanced shell scripts, we will see that it becomes necessary to make our scripts "smarter" by allowing them to make decisions. The fundamental decision making process will start with a conditional statement such as the Bash if statement.