Web Development Tutorials for October 2011

Use PHP to redirect to another page

PHP redirects are useful as they allow you to transparently send a user to a different page. For example, you could want to redirect a user to the home page after they have successfully logged out. There is the option of using meta refresh or some Javascript in your markup to perform the redirection, but the process is smoother and more liquid when it is done on the server side.

Preserve permissions and ownership when copying files using cp

In this tutorial, we will look at copying files in Linux using the cp command and preserving the existing permissions and ownership on the files which are being copied. By default, the cp command will change the owner of the destination files to the person who did the copy. It will also change the permissions on these files to default permissions; usually 644.

Python Substring

This Python substring tutorial covers retrieving substrings from strings. Remember that a substring is simply a part of a bigger string. Since Python treats strings as arrays, we can manipulate strings using array notation to retrieve substrings. This method is also called string slicing.

Getting substrings are useful when parsing data, for example to pull a certain number of characters from a string. Whatever your need for finding substrings is, the Python substring tutorial below will get you up to speed on using substrings in Python.

Python If Statement

The Python if statement is just a regular conditional statement which allows your program to make decisions based on the result of the specified condition.

In this Python tutorial, we will look at the syntax of the Python if statement and how to use it in your Python scripts.

The syntax of the if statement in Python is shown below. As shown, it can be used for multiple conditions:

if condition:
	# do a particular action only if the condition is true
elif other condition:

How to run Python script in Ubuntu Linux

In this tutorial, you will learn how to run Python scripts in Ubuntu using the terminal. The process basically involves invoking the Python interpreter and passing the name of the Python script to be executed as an argument to it.

So if we wanted to invoke a script called helloworld.py which was in the current working directory we would do it like this:

python helloworld.py

The script would then run and execute the instructions that were contained in it.

Install APC on Ubuntu 11.10

In this tutorial, we will look at how to install APC (Alternative PHP Cache) on an Ubuntu system. As we should know, APC is a free and open framework which caches and optimizes the intermediate code generated when interpreting PHP scripts. This improves performance since the PHP scripts don't have to be interpreted every single time they are run. You can think of APC as compiling your PHP scripts into small executable files.

Check uptime Linux

In this tutorial, we will learn how to check the uptime of a Linux/Unix system. Linux and Unix systems allow one to easily check how long the system has been up for. The command which does this is called uptime.

The uptime for a system is very important especially in a server environment where maximum availability is an important requirement. Using the uptime command will help you keep an eye on how well your servers are running and helps you to ensure that they are not rebooting or crashing unnecessarily.

PHP Convert String to Int

In this PHP tutorial, you will learn how to convert a PHP string to int. Depending on what calculation you will be doing with a variable, it may be important that it is of the particular type of integer.

For example, suppose you were processing (from a submitted form) a vote which was from 1 to 10; you would ideally want this data stored in a numeric variable rather than as a string which the $_GET or $_POST array would provide it to you as.

Converting a string to int in PHP is quite easy using casting as we will see below.