Google
 

Tuesday, July 22, 2008

History of PHPBB

phpBB is a popular Internet forum package written in the PHP programming language. The name "phpBB" is an abbreviation of PHP Bulletin Board. Available under the GNU General Public License, phpBB is free software.


phpBB was started by James Atkinson (now a former team member) as a simple UBB-like forum for his own website on June 17, 2000. Nathan Codding and John Abela (both now former team members) joined the development team after phpBB's CVS repository was moved to SourceForge.net, and work on 1.0.0 began. A fully functional, pre-release version of phpBB was made available in July.[2]

phpBB 1.0.0 was released on December 9, 2000, with subsequent improvements to the 1.x codebase coming in two more major installments. The final release in the 1.x line was phpBB 1.4.4, released on November 6, 2001. During the lifetime of the 1.x series, Bart van Bragt, Paul S. Owen (former co-manager of the project), Jonathan Haase (now a former team member) and Frank Feingold joined the team. phpBB 1.x is no longer supported by the phpBB teams, and virtually no websites continue to use it.

phpBB 2.0.x began in February 2001. It was developed entirely from scratch; the developer's ambitions for phpBB had outgrown the original codebase. Doug Kelly (now a former team member) joined the team shortly afterwards. After a year of development and extensive testing, phpBB 2.0.0, dubbed the "Super Furry" version, was released on April 4, 2002, three days later than intended.[3]

phpBB 3.0.x began in late 2002. It was originally intended to be released as phpBB 2.2, and the first planned feature list for 2.2 was announced on May 25, 2003.[4] However, as development progressed, the developers realised that phpBB 2.1.x (the development release cycle for 2.2) had eliminated virtually all compatibility with the 2.0.x line, the version number for release was changed to 3.0.0, in keeping with the Linux kernel versioning scheme.[5] Since then, the development team has seen many internal changes, and many changes to the phpBB3 code have been made. In September 2005, Paul Owen resigned as the Development Team Leader and Meik Sievertsen was promoted as the new Development Team Leader.

In March 2007, the phpBB teams had planned to undergo a short round of server maintenance,[6] however the server crashed during the outage, suffering a double-disk failure and causing phpBB.com to be down for the full week. (The phpBB teams indicated that phpBB, the software, was not the cause of the outage.) However, due to the unexpected outage, the teams decided to change their original plans and launch their brand new website, powered by phpBB3 and the new prosilver theme.[7] This was a big surprise to most, as the theme had been a heavily guarded secret, never before seen by the public, and was originally not intended to be revealed until the final release of phpBB 3.0.0. Initial feedback was split, with many applauding the new theme and others criticising a number of new design decisions, particularly the decision to display the user info on the right side of the viewtopic page (phpBB2's subSilver theme had displayed it on the left).[8]

On April 30, 2007, phpBB founder and co-Project Manager James Atkinson officially resigned from his duties towards phpBB, citing personal circumstances. With the announcement also came the announcement that phpBB was now newly independent, and that the team leaders would be collectively taking charge of the decisions in the future of the project. At the end of May, an announcement was made that Jonathan "SHS`" Stanley, the other co-Project Manager, was stepping down as well for personal reasons.

On July 7, 2007, the teams announced that phpBB had been nominated as a finalist for the SourceForge.net Community Choice Awards in the category of "Best Project for Communications".[9] At the end of the month, SourceForge.net announced that phpBB had won the award for "Best Project for Communications", and in honor of the award, SourceForge.net donated $1000 in phpBB's name to Marie Curie Cancer Care.[10] [11] phpBB also won a "Thingamagoop" from Bleep Labs, and "bragging rights for a full year."[12]

On September 6, 2007, the teams launched the Official phpBB Podcast. The podcast is recorded by a rotating group of phpBB team members with occasional guests, and talk about a number of phpBB-related topics, as well as answering questions e-mailed in from listeners.[13]

The first beta of phpBB3 was released in June 2006,[14] and the first release candidate was released in May 2007.[15] The phpBB3 codebase received an external security audit in September, which was done by SektionEins.[16] Finally, after much fanfare, phpBB 3.0.0 "Olympus" (also dubbed the Gold release) was published on December 13, 2007.[17][18]

phpBB2

phpBB2 is the older of the two packages supported by the phpBB teams. phpBB's website currently refers to it as the "legacy release." It contains far fewer features than its younger counterpart, phpBB3, and also includes an older codebase, supporting PHP 4.0.3 and later. Although most users report no problems running it on PHP 5, the phpBB teams currently do not officially offer support for this configuration.[19] However, many administrators still prefer to run phpBB2 because it provides a much simpler administration interface and has a thriving ecosystem of MODs (modifications) and styles that allow admins many options for customising the software to their liking. Some administrators still run phpBB2 because they have installed so many MODs that they cannot upgrade their board without resetting it.

The default theme in phpBB2 is named subSilver, and was designed by Tom "subBlue" Beddard. At the time that it premiered in 2001, it was a revolutionary new design for bulletin boards, and many bulletin board themes since have borrowed many cues and design elements from subSilver.

The latest release in the 2.0.x line is 2.0.23 which was released on February 17, 2008.[20] Releases in the 2.0.x line are restricted to bug and security fixes only.

Although the phpBB teams are now focusing on phpBB3, they continue to offer support for phpBB2 installations, and will issue a further release of phpBB2 if bugs or security fixes warrant it. However, the PHP Group recently announced that they will be dropping all support for PHP 4 on August 8, 2008, and as a result the phpBB team announced the 2.0.x series would be completely retired, with all official support concluding on February 1, 2009.

Some of phpBB2's major features include the following:

Support for phpBB2 can be obtained in the official phpBB2 Support forum. Full documentation, flash tutorials, and a knowledge base are also available.

[edit] phpBB3

phpBB3 is the current release of the phpBB bulletin board system. Following an eighteen-month beta/release candidate stage, it went gold on December 13, 2007 [22]. It contains many new features that are not found in its older sibling, phpBB2. phpBB3 also provides administrators with much more control over every aspect of the forum software, such as how it is displayed to management of user and group permissions. Consequently, this increased functionality makes the administrative interface much more complex, and new users have found it more intimidating than phpBB2.

phpBB3's default theme is called prosilver. During phpBB3's long development process, prosilver was kept a heavily guarded secret from the public in order to prevent premature copying of the theme and so that it would not spoil the "wow" factor upon the final release of phpBB 3.0.0;[23] however, the unexpected website downtime of March 2007 prompted the teams to change plans and unveil the new theme early. prosilver includes a number of new design concepts over its predecessor subSilver, including a new admin panel without frames and reduced use of tables. One of the more contentious decisions has been to move the user info panel on the viewtopic page to the right in order to provide more focus on the post content. Unlike phpBB2, phpBB3 does not allow the use of HTML tags in comments[24]. A phpBB3 port of the subSilver theme is included with the phpBB3 package and dubbed subsilver2, however an administrator must install it on the board themselves before it is accessible to users.

For the first time, the teams will be quietly pushing out release candidates of minor updates of phpBB3 for "quality assurance testing" prior to general release.[25] These candidates are intended to prevent the possibility of significant bugs being produced by minor updates, thus causing a subsequent critical update to be released within days of the original. (This scenario happened twice during the 2.0.x line and once during phpBB's release candidate stage in 2007.) A mailing list is open to anyone interested in testing these "quality assurance" releases when they are available.

The latest in the 3.x line is phpBB 3.0.2, code named "Olympus", released on July 10, 2008[26]. phpBB3 requires PHP 4.3.3 or later and is fully compatible with PHP 5.

Some of phpBB3's major features include:

The phpBB website includes a non-exhaustive list of phpBB3 features. A comparison page is also available on their website, comparing the features between phpBB3 and other bulletin board systems.

Support for phpBB3 can be obtained in the official phpBB3 Support forum. Full documentation, flash tutorials, and a knowledge base are also available.

[edit] Future development

The Development Team has begun working on phpBB 3.1.x, the development line for phpBB 3.2. Planned features have not yet been officially announced, however the teams have revealed[27] that the new version will include a new events system, a completely rewritten BBCode system, RSS feed support, the ability to edit the FAQ, and more. The phpBB teams maintain a website for phpBB development at Area51. The teams have revealed that phpBB 3.1 will be code-named "Ascraeus," named after Ascraeus Mons, the second tallest mountain on Mars. (Olympus Mons, which 3.0 was named after, is the tallest.)

Current developers are:

  • Acyd Burn - (Meik Sievertsen)
  • APTX - (Marek A. R.)
  • DavidMJ - (David M.)
  • Kellanved - (Henry Sudhof)
  • naderman - (Nils Adermann)
  • ToonArmy - (Chris Smith)
  • Vic D'Elfant - (Vic D'Elfant)

[edit] MODs

MODs are code modifications created by the phpBB community, often used to extend the functionality of or change the display of phpBB. The term is capitalised to distinguish modifications from forum moderators. Modifications referred to in this manner are not authored by the phpBB developers, and do not enjoy the same level of support as unmodified official code. The phpBB MOD Team accepts modifications from community sources for validation, and modifications which meet the MOD Team's standards are made available for download from the phpBB MOD Database. Other sites also provide phpBB2 and phpBB3 modifications for download. Some of the sites have their own standards which they validate to, and other sites do not do any validation, however the phpBB teams do not offer support for boards using MODs downloaded from sites other than phpBB.com. Documentation for phpBB3 MODding is provided by the MOD Team.

[edit] Security

In December 2004, a large number of Web sites were defaced by the Santy worm, which used vulnerabilities in outdated versions of phpBB2 to overwrite PHP and HTML pages.[28] Although these were the result of outdated versions of PHP and phpBB, incidents like these have caused the security of phpBB to be disputed. There have also been a few times where new releases of phpBB have come out a few days apart, although the last occurrence of this was in early 2005.[29] However, the phpBB Team usually responds to security reports as soon as possible, and releases a new version quickly. The phpBB Group has also learned from a series of security issues, and phpBB 2.0.18 was released following a codebase security audit.[30] The phpBB 3.0.x codebase has also received a security audit, which resulted in the release of phpBB 3.0 RC6.[31]

Additionally, many things have been changed in phpBB2 to avoid problems in the future, including many features backported from the phpBB3 codebase. Among those are a re-authentication system for the administration panel (introduced after a cookie verification issue allowed attackers to gain administrator access[32]), a visual confirmation system (CAPTCHA) to prevent bots from registering, as well as the substitution of the highlighting code, which was the cause for critical vulnerabilities in phpBB 2.0.10 and 2.0.15. In order to keep boards as secure as possible, administrators are urged by the teams to keep their board updated to the latest version.

In November 2005, the phpBB Group announced a new Incident Investigation Team (IIT), a sub-team of their Support Team, which is responsible for assisting users in the cleanup and repair of an attacked phpBB installation and investigating reports of new exploits.[33] The team announced a tracker the following January where administrators of attacked bulletin boards could report an attack and receive support from the IIT.[34]

The CAPTCHA system in phpBB2 has proven vulnerable to automated registrations, with numerous phpBB-based forums being swamped by spam registrations. Due to the feature freeze, the antispam solutions have to be installed separately. The phpBB team has published recommendations[35] on protecting the boards from spam. At the moment, the best method is to use a question-answer challenge, implemented by Textual Confirmation or Registration Auth Code MODs.[citation needed] phpBB3 has a much stronger CAPTCHA system, however during the phpBB3 development/beta phase it was frequently criticised for being difficult to read.[36] The development team, however, has been working on improving its readability prior to phpBB3's final release.

phpBB3 has enjoyed additional attention from the teams in the area of security, and was completely rewritten to have a more secure code base than phpBB2. The phpBB3 codebase received an external security audit in September 2007, which was done by SektionEins. The sixth release candidate of phpBB3 was published following the results of the security audit.[37] Additionally, the teams have announced that each minor release of phpBB3 (3.0.1, 3.0.2, etc.) will be preceded by individual release candidates in an effort to prevent instances where subsequent releases would be only days apart (as happened a couple of times during the 2.0.x line).[38]

reference:http://en.wikipedia.org/wiki/PhpBB

Thursday, July 17, 2008

PHP HTML Form Example

Use this example as a form walkthrough. We will briefly build an HTML form, and call the form data using PHP. PHP offers several methods for achieving this goal, so feel free to substitute alternative methods as you follow along. Our example will show you a method using a single .php file, combining both PHP and HTML in one simple text file, to retrieve the data and display the results. Below is a quick review of bullets, check boxes, text fields, and input fields and using them to build a form to retrieve some personal information about our user.

Building the HTML Form

Step 1 is to build the form document to retrieve user date. If you already experienced using HTML forms, this should be review, however, if not we recommend a brief visit through the Tizag HTML Forms Tutorial. The code below shows a simple html form document set up to retrieve some personal knowledge about our user.

Input Fields

Input fields are the simplest forms to grasp. As mentioned in the Forms Tutorial, just be sure to place the name attribute within the tags and specify a name for the field. Also be aware that for our form's action we have placed the $PHP_SELF super global to send our form to itself. We will be integrating more PHP code into our form as we continue on so be sure to save the file with a .php extension.

Code:



Personal INFO


">
First Name:name="Fname">:

Last Name:name="Lname">:

Radios and Checkboxes

The catch with radio buttons lies with the value attribute. The text you place under the value attribute will be displayed by the browser when the variable is called with PHP.

Check boxes require the use of an array. PHP will automatically place the checked boxes into an array if you place [] brackets at the end of each name.

Code:

...
Gender::

Male::

Female::

Please choose type of residence::

Steak::

Pizza::

Chicken::

Textareas

In reality, textareas are oversized input fields. Treat them the same way, just be aware of the wrap attribute and how each type of wrap will turn out. PHP relys on this attribute to display the textarea.

Code:

...
:

Drop Down Lists & Selection Lists

These two forms act very similar to the already discussed radio and checkbox selections. To name a selection form, place the name attribute within the select tags at the beginning of the form, and then place the appropriate value to fit each option.

Code:

...
Select a Level of Education:

:

Select your favorite time of day::

:

Be sure to check through your code to double check for bugs or errors especially look at each name attribute to be sure your names are all correct. As far as names go, you can copy the ones shown or simply make up your own, just be sure you remember what they are. Your form should be similar to the one shown here.

Display:


First Name:
Last Name:
Gender:
Male:
Female:
Favorite Food:
Steak:
Pizza:
Chicken:

Select a Level of Education:

Select your favorite time of day:


Wednesday, July 16, 2008

Active Server Pages: Subroutines and Include/virtual

Subroutines

Subroutines have the same utility in ASP as it has in other languages.

In the next two examples, we have asked our visitors his name, and depending on that answer a different response is sent to the client. The response will be the same in both cases, but in the second one subroutines are used. The use of subroutines may be very useful when there are a lot of instructions to be perform within a subroutine. This way it will allow us to simplify the structure of our script.

Example 1
<%
TheName=request.form("name)

if TheName="John" then
response.write ("Hi, John. How are you?")
response.write ("
Did you know I got married last month?")
else
response.write ("Hi. How are you?")
end if
%>
Example 2
<%
TheName=request.form("name)

if TheName="John" then
ResponseToJohn()
else
ResponseToUnknown()
end if

Sub ResponseToJohn()
response.write ("Hi, John. How are you?")
response.write ("
Did you know I got married last month?")
End Sub

Sub ResponseToUnknown()
response.write ("Hi. How are you?")
End Sub

%>

In order to call a subroutine, we will use this kind of code:

Whatever()

Where Whatever is the name of the subroutine (it is recommended to use a very descriptive name of the task we want to perform within the subroutine to make it easier to understand the script). We may also provide information to the subroutine in order to perform the specified task. The data will be provided this way:

Whatever(data1, data2 ... dataN)

In the following example we will provide different data to a unique subroutine depending on the Name of the person provided throw a form:

Example 3
<%
TheName=request.form("name)

if TheName="John" then
ResponseToVisitor(35,Sue,New York)
else
if TheName="Peter" then
ResponseToVisitor(33,Sally,Los Angeles)
else
response.write("Who are you?")
end if
end if

Sub ResponseToVisitor(AA,BB,CC)
response.write ("I know your are" & AA & "years old, ")
response.write ("you are married to" & BB & ", and")
response.write ("you are living in " & CC)
End Sub
%>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

In line 14 it is specified AA is the first variable to be get, BB the second one, and CC the third one. The values for the three variables are provided in the same order in line 5 or line 8.

The example above also shows subroutines are very useful to avoid repeating a specific number of tasks several times within the script, so that the script looks more organized and it is smaller.


Include/virtual

Server Site includes or SSI is a very simple programing language (see a small tutorial) but it also has a very limited number of instructions. We will consider only one option SSI allows us to use within our asp scripts: include/virtual.

In the next example we will use the include option of SSI in a our asp script (response.asp). This command allows as to add a set of instructions from different files (file1.txt and file2.txt bellow) and execute them.

Example 4
response.asp
<%
TheName=request.form("name)

if TheName="John" then
%>

<% else %>

<%
end if %>
File1.html
Hi, John.

I know your are 31 years old, you are married to Sue, and you are living in New York.
File2.asp
<%
for i=1 to 3
response.write(Thename & "...
")
next
response.write("Who are you?")
%>



In this case, if the name of the person who is visiting our page is John, then we will respond with file1.html. If not, then we will execute some asp instructions from file2.asp.

The include file must be a text file (.txt, .html, .htm, .shtml, .asp...). Although we have used file1.html and file2.asp, the script will work exactly in the same way with file1.txt and file2.txt (changing the name of the files would have no effect).


By using SSI and asp we may also get a secret page:

secret_page.asp Try !
<%
UserName=request.form ("username")
Password=request.form("password")
if UserName="myusername" and Password="mypassword" then
%>

<% else %>

Username:

Password:



<% end if %>
secret_info.txt
This is my secret information:

My name is John.

My surname is Smith.


End of secret information.

In this case it is convenient to save secret_info.txt file in the cgi-bin directory (the .txt file is not accessible by visitors from this directory, but it will be accessible from our top directory).

Active Server Pages: Do...Loop / Select...Case instructions

Do While...Loop

Again, we will define a condition and one or more instructions:

<%
mynumber=0
Do While mynumber<10> response.write("Hello
")
mynumber=mynumber+1

Loop
%>

In this example the condition is "mynumber<10">

Do Until....Loop

Quite similar to the previous one, it also includes a condition and one or more instructions:

<%
mynumber=0
Do Until mynumber=10

response.write("Hello


")
mynumber=mynumber+1

Loop
%>

In this example the condition is "mynumber=10", so mynumber will increased until it is equal to 10, and then the loop will be abandon.

Let's see an example using this Do Until...Loop:

<%
myfirstnumber=0
mysecondnumber=0

Do Until myfirstnumber=15

Do Until mysecondnumber=15
response.write("X")
mysecondnumber=mysecondnumber+1
Loop
Response.write ("
")
myfirstnumber=myfirstnumber+1
mysecondnumber=myfirstnumber

Loop

Response.write ("END")
%>

The result of the script is this one:

XXXXXXXXXXXXXXX
XXXXXXXXXXXXXX
XXXXXXXXXXXXX
XXXXXXXXXXXX
XXXXXXXXXXX
XXXXXXXXXX
XXXXXXXXX
XXXXXXXX
XXXXXXX
XXXXXX
XXXXX
XXXX
XXX
XX
X
END

Select Case....End Select

This is a very useful instruction in case we want to check different values for variable. Lets check an example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<%
mynumber=3
Select Case mynumber
Case 1
Response.write ("Number 1")
Case 2
Response.write ("Number 2")
Case 3
Response.write ("Number 3")
Case 4
Response.write ("Number 4")
Case 5
Response.write ("Number 5")
Case Else
Response write ("Mynumber is higher than 5")
End Select
%>

In this example above, we have defined mynumber as 3, so they are executed the instructions following line 8 (in this case only one instruction is executed, but they may be several instructions). Case Else is not necessary.

Let's try a second example:

1
2
3
4
5
6
7
8
9
10
11
12
13
<%
username=request.form("username")
Select Case username
Case "Peter"
Response.write ("Hello, Peter")
Case "John"
Response.write ("Hello, John")
Case "Joe"
Response.write ("Hi, Joe")
Case Else
Response write ("I do not know you")
End Select
%>

Let's see a different example:

backgroundform.html

Chose background color

Which color do you prefer to use as your background?



Defined color




Custom color





backgroundresponse.asp
<%
kindofcolor=Request.form("kindofcolor")

Select Case kindofcolor
case "defined"
colorofbackground=Request.form("definedcolor")
Select Case colorofbackground
case "#FFFFFF"
texttoshow="White"
case "#FF0000"
texttoshow="Red"
case "#00FF00"
texttoshow="Green"
case "#0000FF"
texttoshow="Blue"
End select
case "custom"
colorofbackground=Request.form("mycolor")
texttoshow="Custon color"
End select
%>


Chose background color
">


<% =texttoshow %>





You may try this example:

Which color do you prefer to use as your background?
Defined color
Custom color

Active Server Pages: If...Then...Else / For...Next Instructions

If....Then...Else

The If....Then...Else instructions sequence is very similar to the one we may find in different kind of scripting languages. Let's check an example.

<%
AA="water"

If AA="water" Then
response.write ("I want to drink water")
Else
response.write ("I want to drink milk")

End If
%>

We may use it this way:

<% AA="water"
If AA="water" Then %>

I want to drink water

<% Else %>

I want to drink milk

<% End If %>

In both cases we have checked a condition (AA="water"), and we have get a positive instruction (to write the sentence "I want to drink water"). We are allowed to execute any kind of instructions (including If....then....Else) and as many instructions as we want .

For....Next

This instructions is also similar in different programming languages. Let's see a typical example.

example.asp Try !
I want to say "Hello" 10 times

<% For mynumber = 1 to 10 %>
<% =mynumber %> Hello

<% Next %>
END

In this case we have defined a variable ("mynumber") and using the For...Next instruction we have repeated 10 times line 4. Similarly to If....Then....Else instruction, we are allowed to execute any kind of instructions and as many of them as we want .

The For...Next instruction allows to define the value of the increment.

<% For mynumber = 1 to 20 STEP 2
response.write("Hello
")
Next %>
<% For mynumber = 20 to 1 STEP -2
response.write("Hello
")
Next %>

In both cases we will get the same response ("Hello" 10 times). The increment may be positive or negative as shown in the example.

Active Server Pages: Using Variables, and Forms

Using Variables, and Forms in Active Server Pages

Forms are a convenient way to communicate with visitors to your Web site. Using forms, you can create a survey form and ask visitors to fill it out. When they fill out the form, you can process the results automatically.

With forms, there are two steps: first you create the form, and then you process it. To create a form for an Active Server Page, just create a standard HTML form.

To try out this example, create an HTML file ("form_response.html") and cut-and-paste the following text into it.

form_response.html try !

Asking for information


Your name: name" size="20">

Your email: email" size="15">




Active Server Pages provide a mechanism for processing forms that, unlike CGI scripting, doesn't involve serious programming: the Request.Form.

Considering the form above, we may create the file bellow and get a response.

form_response.asp try !

Responding to a form

Your name is <% =Request.Form("name") %>

Your email is <% =Request.Form("email") %>

To display the contents of each field in the form, type:

<% =Request.Form(fieldname) %>
where fieldname is the name of the field.

Creating a Variable

You'll probably want to do more with your forms than display their contents in a Web page. For example, based on the contents of the form, you may want to create a variable and insert that variable in different places of your response page. You may need to create a variable. To do that, just make up a name and set it equal to the contents of the field.

For example, if you have a field called "CatName" in your form, you can save it into a variable called "TheName" by typing:

<% TheName = Request.Form("CatName") %>
If you want to display "VisitorName" several times within a text you only need to include the variable in the text. For example:

My cat´s name is <% =TheName %>. Do you want to see <% =TheName %>?.

Example

The form in this example asks users to introduce their names and their favorite color: red, blue, or green. When the form is received, the server responds displaying these data.
nameandcolor.html try !

Name and Color


Let me know your Name and Favorite Color:

YOUR NAME:
YOURNAME" SIZE=20>

COLOR:
COLOR" VALUE="1" CHECKED>Red
COLOR" VALUE="2">Green
COLOR" VALUE="3">Blue





Now, create an ASP file ("nameandcolor.asp") and cut-and-paste the following text into it.

nameandcolor.asp try !

Name and Color

<% TheName = Request.Form("YOURNAME") %>
<% colornumber = Request.Form("COLOR") %>
Hi, <% =Thename %>.

I know your favorite color is
<% if colornumber = "1" then %>
red
<% end if %>
<% if colornumber = "2" then %>
green
<% end if %>
<% if colornumber = "3" then %>
blue
<% end if %>.


Active Server Pages: Displaying Date, Time and Text

Displaying the Current Date and Time
The date and time described in this section are those that are on the server.
Date
To display the current date by itself in a Web page, type:

<% =date %>

at the point where you want it to appear. When you view the page in your browser, you should see something like this:

Thu, Jan 23, 1997

Note: Even though "=date" is a short script, it's actually made up of two parts. The "date" part tells the server, "Get me the date." The equal sign (=) tells the server to display the date in the Web page. If you typed just:

<% date %>

the server would get the current date from your system, but that's all. It wouldn't display it. There are times when it makes sense to use an ASP function without the equal sign.
Time
To display the current time by itself, type:

<% =time %>

where you want it to appear. When you view the page, you should see something like this:

4:19:46 PM
Now (Date and Time)
To display the current date and time, type:

<% =now %>

where you want them to appear. When you view the page, you should see something like this:

1/23/97 4:19:46 PM
Changing the Way Date and Time are Displayed
You can also use Active Server Pages (ASP) functions to customize the way the current date and time are displayed on your Web page. To do this, use the now function together with the following formatting functions.
Month and Monthname
To display the number of the current month in a Web page, type:

<% =month(now) %>

where you want it to appear. When you view the page in your browser, you'll see a 1 if the current month is January, 2 if it's February, and so on.

To display the name of the current month, type:

<% =monthname(month(now)) %>

where you want it to appear.
Day
To display the day of the current month, type:

<% =day(now) %>

where you want it to appear. When you view the page, you'll see a number between 1 and 31.
Year
To display the current year, type:

<% =year(now) %>

where you want it to appear.
Example
Suppose you wanted to display today's date as day/month/year instead of month/day/year. To do so, you would use the day, month, and year ASP functions together, by typing:

<% =day(now) %>/<% =month(now) %>/<% =year(now) %>

When you viewed the page, you would see something like this:

23/1/1997

Later we'll see how you can change this so only the last two digits of the year are displayed, like this:

23/1/97
Weekday and Weekdayname
To display the day of the week as a number from 1 to 7 in a Web page, type:

<% =weekday(now) %>

where you want it to appear. When you view the page in Internet Explorer, you'll see a 1 if today is Sunday, 2 if it's Monday, and so on.

To display the day of the week by name, type:

<% =weekdayname(weekday(now)) %>

where you want it to appear.
Hour, Minute, and Second
To display just the hour part of the current time, type:

<% =hour(now) %>

where you want it to appear. The hour function is based on a 24-hour clock. When you view the page, you'll see a number between 0 and 23.

To display just the minutes part of the current time, type:

<% =minute(now) %>

where you want it to appear. When you view the page, you'll see a number between 0 and 59.

To display just the seconds part of the current time, type:

<% =second(now) %>

where you want it to appear. When you view the page, you'll see a number between 0 and 59.
Example
Try typing this into a Web page:

The time is <% =time %>. That means it's <% =minute(now) %>
minutes past <% =hour(now) %> o'clock.

When you view the page in Internet Explorer, you should see something like this:

The time is 1:36:05 PM. That means it's 36 minutes past 13 o'clock.

Remember, the hour function is based on a 24-hour clock. Later we'll see how to convert from the 24-hour clock to a 12-hour clock.
Timevalue
You probably won't ever use the timevalue function. It takes the different ways you can write the time, such as "2:24PM" and "14:24," and returns them in this format: "2:24:00 PM." This can be useful if you're using a function that needs to be given the time in that exact format.
Example
Earlier in this section we saw how you can use the hour, minute, and second functions to break up the time into hours, minutes, and seconds. With the timevalue function, you can put them back together. Type this into a Web page:

When it's 23 minutes and 5 seconds past 4 o'clock in the afternoon,
that means it's <% =timevalue("16:23:05") %>.
This is the same as <% =timevalue("4:23:05PM") %>
or <% =timevalue("16:23:05PM") %>.

Make sure you type "16:23:05PM" and not "16:23:05 PM." The "05" and the "PM." should be run together, not separated by a space. When you view the page in Internet Explorer, you should see:

When it's 23 minutes and 5 seconds past 4 o'clock in the afternoon, that means it's 4:23:05 PM. This is the same as 4:23:05 PM or 4:23:05 PM.
Displaying Text
len
The len function tells you how many characters are in a word or sequence of words. (The name "len" is an abbreviation of "length.") All characters are counted, including the space character. For example, to find the length of the sentence "The cat is on the mat," type this into a Web page:

There are <% =len("The cat is on the mat.") %> characters in
"The cat is on the mat."

When you view the page in Internet Explorer, you should see this:

There are 22 characters in "The cat is on the mat."
left
You can use the left function to look at the first few characters of a word or sequence of words. For example, to find the first character of "Frankenstein," type this into a Web page:

"Frankenstein" begins with the letter <% =left("Frankenstein", 1) %>.

When you view the page, you should see this:

"Frankenstein" begins with the letter F.
right
To look at the last few characters of a word or sequence of words, use the right function. For example, to find the last three letters of "Wednesday," type this into a Web page:

The last three letters of "Wednesday" are: <% =right("Wednesday", 3) %>.

When you view this page, you should see this:

The last three letters of "Wednesday" are: day.
Example
What if you wanted to take a few letters from the middle of something? How would you specify exactly where in the middle you wanted to be? For example, how would you take out just the "apple" part of the word "pineapples"?

You could start with the fifth character from the left and then stop at the second character from the right. Or you could do it the following way.

Try typing this into a Web page:

<% =right("pineapples", 6) %> <% =left(right("pineapples", 6), 5) %>

This line takes the last six letters of the word "pineapples," which make up the word "apples." Then it takes the first five letters of the word "apples," which make up the word "apple."

When you view this page in Internet Explorer, you should see this:

apples apple

Then try typing this into a Web page:

<% =left("pineapples", 9) %> <% =right(left("pineapples", 9), 5) %>

This line takes the first nine letters of the word "pineapples," which make up the word "pineapple." Then it takes the last five letters of the word "pineapple," which make up the word "apple."

When you view this page, you should see this:

pineapple apple
Cool Things You Can Do with Date, Time, and Text
Here are some examples of interesting things you can do with date, time, and text functions.
Link of the Day
What if you wanted to have a link that pointed to a different page every day of the week? Here's how you can do that. First, choose the pages (HTML files) on your Web site that you want your link to point to. Name them "Sunday.htm," "Monday.htm," and so on. (If you don't have seven different HTML files, you can copy some of the files or make aliases on your Macintosh to them. The important thing is that there has to be one file or alias for every day of the week.)

To make the link, type

.htm>Link of the Day

where you want it to appear. When you click this link in Internet Explorer, it will take you to today's page.
Another Way to Display Today's Date
Earlier we saw how to change the date display from month/day/year to day/month/year like this:

23/1/1997

We can also change the date display so only the last two digits of the year are included. To do this, type

<% =day(now) %>/<% =month(now) %>/<% =Right((year(now)), 2) %>

Now when you view the page, you should see something like this:

23/1/97
Another Way to Display the Time
In an earlier example, we wrote a server-side script to display the current time in words, such as: "The time is 36 minutes and 5 seconds past 13 o'clock." This script used the ASP hour function, which returns just the hour part of the current time, based on a 24-hour clock.

In this example, we'll see how to change 24-hour clock times such as "13 o'clock" to 12-hour clock times ("1 o'clock PM"). To do this, we'll need to make the server-side script that uses the hour function a little more complicated. Instead of

<% =hour(now) %> o'clock

we'll need to write a script that looks at the hour and does one of the following:

* If the hour is 0 (zero), the script displays "midnight."
* If the hour is 12, the script displays "noon."
* If the hour is between 1 and 11, the script doesn't change it, but it displays "AM" after "o'clock."
* If the hour is between 13 and 23, the script subtracts 12 (to make it a number between 1 and 11) and displays "PM" after "o'clock."

The script is shown below. It isn't written quite the way a programmer would write it, but it works, and it's fairly easy to understand, since it follows the items in the bulleted list above exactly.

The hour is
<% if hour(now) = 0 then %>
midnight.
<% end if if hour(now) = 12 then %>
noon.
<% end if if (hour(now) >= 1) and (hour(now) <= 11) then %>
<% =hour(now) %> o'clock AM.
<% end if if (hour(now) >= 13) and (hour(now) <= 23) then %>
<% =hour(now) - 12 %> o'clock PM.
<% end if %>

If you type (or better yet, cut-and-paste) this script in a Web page, when you view the page, you should see something like this:

The hour is 4 o'clock PM.