Tag Archive for 'tutorial'

Introduction to Life Assurance Products

In this post, we'll describe the main types of life assurance.  The plan is to do so in a which which is as easy to understand as possible.  I originally wrote this article on Google's knol, and while there is a slight actuarial slant to it, it doesn't go into the valuation of life assurance products, or use actuarial notation, however posts on those topics may be added in the future.

The main characteristic of life assurance is that it provides a sum of money (the benefit), which depends on whether the policyholder (the life assured) dies or survives during the contract.  For example, one of the simplest forms is life assurance which will pay a sum of money when the policyholder dies. In return for this, the policyholder will pay premiums to the insurance company.

Continue reading 'Introduction to Life Assurance Products'

Exporting from Movable Type to WordPress

Slightly off topic post for this blog, but I'd like to share my experiences of moving a blog from Movable Type 4 to WordPress 3.4 blogging software.

The reason I chose to switch was that, while MovableType produces static web pages which are quick to load on a slow webserver, the interface felt too cluttered - almost like it is trying to do too many things.  To top it off, it was suggesting that I link to certain "promoted" sites which is an immediate turn off.

I've exported from MovableType in the past, and encountered a few issues, but this time seemed to go much smoother.  Perhaps it is partly due to having a smaller blog, or perhaps the process has improved.  This article has a guide showing the steps I followed to move all my posts across to a fresh install of WordPress.

Continue reading 'Exporting from Movable Type to WordPress'

How to password protect your spreadsheets in Excel 2007 or Excel 2010.

The option to require a password to open an Excel spreadsheet may be in a different place than you are used to in earlier versions of Excel. Follow the steps below to require a password to protect your spreadsheet.

  1. Choose File -> Save As.
    File -> Save As

Continue reading 'How to password protect your spreadsheets in Excel 2007 or Excel 2010.'

How to use the query string in PHP

This article tells you how to pass variables to a PHP page using the query string, and how to access them from that page.

Introduction

Have you ever seen a URL which looked like "www.example.com/page.php?mode=1&style=red"? Well, this page is being passed variables and their values through the query string, here the variables "mode" and "style" are being passed, with values "1" and "red" respectively. The question mark indicates the start of the query string and the ampersand, &, symbol seperates variable=value assignments. The page is then able to read these variables and react according to them, for example to display them to the user.

Passing a query string to a page

There are two ways to pass a QueryString to a page, the first is to enter it manually, for example:

<a href="page.php?mode=1">Mode 1</a>

The above HTML creates a link to a page passing the variable mode with the value "1".
Continue reading 'How to use the query string in PHP'

How to Find the Current URL with PHP

The full URL to a page comes in three parts: The domain name, the path to the file then the filename, and the query string. For example, take the URL http://www.example.com/example/page.php?name=Bob. The three parts of this are:

1. The domain name: www.example.com
2. The path to the page: /example/page.php
3. The query string: name=Bob

So how do you find it all out with your own PHP scripts?

Continue reading 'How to Find the Current URL with PHP'

Find a visitor's IP Address with PHP

Do you want to know the IP address of a visitor? This can be useful for many reasons, such as tracking site usage or blocking access to specific people. Here's how you can find it using PHP.

In a PHP page, within the PHP tags, <?php ... ?>, you can retrieve the IP address of a user through the server variables array, which is contains information about the user and the server environment and is accessible from anywhere in your PHP script. To do this, you use the code $_SERVER['REMOTE_ADDR']. It works like a normal array, where REMOTE_ADDR is the key, and the IP address of the visitor is the value associated with that key.

Display The IP Address

So, if you want to display the IP Address to the user then the following page will suffice:

<?php
echo "Hello! Your IP Address is: " . $_SERVER['REMOTE_ADDR'];
?>

Continue reading 'Find a visitor's IP Address with PHP'

How to use the QueryString in ASP

This article tells you how to pass variables to an ASP page using the QueryString, and how to access them from that page.

Have you ever seen a URL which looked like "www.example.com/page.asp?mode=1&style=red"? Well, this page is being passed variables and their values through the QueryString, here the variables "mode" and "style" are being passed, with values "1" and "red" respectively. The question mark indicates the start of the query string and the ampersand, &, symbol seperates variable=value assignments.

The page is then able to read these variables and react according to them, for example to display them to the user.

Passing a QueryString to a page

There are two ways to pass a QueryString to a page, the first is to enter it manually, for example:

<a href="page.asp?mode=1">Mode 1</a>

The above HTML creates a link to a page passing the variable mode with the value "1".

An alternative, and perhaps more useful, way is to use HTML forms. The main thing to remember with forms is that you need to use the GET method to send information via the QueryString, for example:

<form method="GET" action="page.asp">
Please enter your name: <input type="text" name="username" />
<input type="submit" value="submit" />
</form>

This code displays a simple HTML form with a text box and a submit button. When the user enters their name and presses submit, the information in the name box is passed to a page called "page.asp" (specified in the form's action attribute) via the QueryString. So, if I entered "tiposaurus" and pressed submit, the form will call page.asp?username=tiposaurus. Remember that "username" was what we entered as the text input's name attribute.

Accessing a QueryString element in ASP

In ASP, all the information passed via the QueryString is held in the Request.QueryString collection. To access an item, type Request.QueryString("varName"), where varName is the name of the variable in the QueryString.

To demonstrate, let's create page.asp to process the information from the form above:

<%@language="VBScript"%>
<% If Request.QueryString("username") "" Then
Response.Write "Hello, " & Request.QueryString("username")
Else
Response.Write "You did not enter a name."
End If
%>

So now, me typing in tiposaurus and pressing submit will generate the reply "Hello, tiposaurus".

Listing the contents of Request.QueryString

Should you wish to find out everything that's in the QueryString, you can do so with the following code which displays the variables next to their values in a table:

<%@language="VBScript"%>
<table border="1">
<tr><th>variable</th> <th>value</th></tr>
<%
Dim variable
For Each variable in Request.QueryString
Response.Write "<tr><td>" & variable & "</td>"
Response.Write "<td>" & Request.QueryString(variable) & "</td></tr>"
Next
%>
</table>

Conclusion

This article showed you how to pass information between pages with the QueryString, and a use which allows you to add some increased interactivity. There are a lot of other uses, for example selecting which section of a site to display based on a variable in the QueryString, and processing form data.

How to Find the Current URL in ASP

The full URL to a page comes in three parts: The domain name, the path to the file then the filename, and the QueryString. For example, take the URL http://www.example.com/example/page.asp?name=Bob. The three parts of this are:

1. The domain name: www.example.com
2. The path to the page: /example/page.asp
3. The QueryString: name=Bob

So how do you find it all out with your own scripts?

Well the following code should do it:

<%@language="VBScript"%>
<%
  Dim strDomain, strPath, strQueryString, strURL
  ‘ find out the domain:
  strDomain = Request.ServerVariables("HTTP_HOST")
  ‘ find out the path to the current file:
  strPath = Request.ServerVariables("URL")
  ‘ find out the QueryString:
  strQueryString = Request.ServerVariables("QUERY_STRING")
  ‘ put it all together:
  strURL = "http://" & strDomain & strPath & "?" & strQueryString
  Response.Write "The current URL is: " & strURL
%>

Find a visitor's IP Address in ASP

Do you want to know the IP address of a visitor? This can be useful for many reasons, such as tracking site usage or blocking access to specific people. Here's how you can find it.

In an ASP page, within the ASP tags, <% ... %>, you can retrieve the IP address of a user through the ServerVariables collection of the Request object. To do this, you use the code Request.ServerVariables("REMOTE_ADDR").

Continue reading 'Find a visitor's IP Address in ASP'

Write text on a dynamically generated image using PHP

This tutorial will tell you how to write text to a blank dynamically generated PNG image in PHP. This is fairly simple, so it will just be the first step in a series of tutorials dealing with images in PHP. The image functions require the GD library to be installed.

Continue reading 'Write text on a dynamically generated image using PHP'