You are on page 1of 79

lectures/2/src/froshims/froshims0.

php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.

<?
/*************************************************************
* froshims0.php
*
* David J. Malan
* malan@harvard.edu
*
* Implements a registration form for Frosh IMs.
* Submits to register0.php.
*****************************************************************/
?>
<!DOCTYPE html>
<html>
<head>
<title>Frosh IMs</title>
</head>
<body>
<div style="text-align: center">
<h1>Register for Frosh IMs</h1>
<br><br>
<form action="register0.php" method="post">
<table style="border: 0; margin-left: auto; margin-right: auto; text-align: left">
<tr>
<td>Name:</td>
<td><input name="name" type="text"></td>
</tr>
<tr>
<td>Captain:</td>
<td><input name="captain" type="checkbox"></td>
</tr>
<tr>
<td>Gender:</td>
<td>
<input name="gender" type="radio" value="F"> F
<input name="gender" type="radio" value="M"> M
</td>
</tr>
<tr>
<td>Dorm:</td>
<td>
<select name="dorm">
<option value=""></option>
<option value="Apley Court">Apley Court</option>
<option value="Canaday">Canaday</option>
<option value="Grays">Grays</option>
<option value="Greenough">Greenough</option>

lectures/2/src/froshims/froshims0.php
49.
<option value="Hollis">Hollis</option>
50.
<option value="Holworthy">Holworthy</option>
51.
<option value="Hurlbut">Hurlbut</option>
52.
<option value="Lionel">Lionel</option>
53.
<option value="Matthews">Matthews</option>
54.
<option value="Mower">Mower</option>
55.
<option value="Pennypacker">Pennypacker</option>
56.
<option value="Stoughton">Stoughton</option>
57.
<option value="Straus">Straus</option>
58.
<option value="Thayer">Thayer</option>
59.
<option value="Weld">Weld</option>
60.
<option value="Wigglesworth">Wigglesworth</option>
61.
</select>
62.
</td>
63.
</tr>
64.
</table>
65.
<br><br>
66.
<input type="submit" value="Register!">
67.
</form>
68.
</div>
69.
</body>
70. </html>

lectures/2/src/froshims/froshims1.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.

<?
/*************************************************************
* froshims1.php
*
* David J. Malan
* malan@harvard.edu
*
* Implements a registration form for Frosh IMs.
* Submits to register1.php.
*****************************************************************/
?>
<!DOCTYPE html>
<html>
<head>
<title>Frosh IMs</title>
</head>
<body>
<div style="text-align: center">
<h1>Register for Frosh IMs</h1>
<br><br>
<form action="register1.php" method="post">
<table style="border: 0; margin-left: auto; margin-right: auto; text-align: left">
<tr>
<td>Name:</td>
<td><input name="name" type="text"></td>
</tr>
<tr>
<td>Captain:</td>
<td><input name="captain" type="checkbox"></td>
</tr>
<tr>
<td>Gender:</td>
<td>
<input name="gender" type="radio" value="F"> F
<input name="gender" type="radio" value="M"> M
</td>
</tr>
<tr>
<td>Dorm:</td>
<td>
<select name="dorm">
<option value=""></option>
<option value="Apley Court">Apley Court</option>
<option value="Canaday">Canaday</option>
<option value="Grays">Grays</option>
<option value="Greenough">Greenough</option>

lectures/2/src/froshims/froshims1.php
49.
<option value="Hollis">Hollis</option>
50.
<option value="Holworthy">Holworthy</option>
51.
<option value="Hurlbut">Hurlbut</option>
52.
<option value="Lionel">Lionel</option>
53.
<option value="Matthews">Matthews</option>
54.
<option value="Mower">Mower</option>
55.
<option value="Pennypacker">Pennypacker</option>
56.
<option value="Stoughton">Stoughton</option>
57.
<option value="Straus">Straus</option>
58.
<option value="Thayer">Thayer</option>
59.
<option value="Weld">Weld</option>
60.
<option value="Wigglesworth">Wigglesworth</option>
61.
</select>
62.
</td>
63.
</tr>
64.
</table>
65.
<br><br>
66.
<input type="submit" value="Register!">
67.
</form>
68.
</div>
69.
</body>
70. </html>

lectures/2/src/froshims/froshims2.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.

<?
/***********************************************************************
* froshims2.php
*
* David J. Malan
* malan@harvard.edu
*
* Implements a registration form for Frosh IMs.
* Submits to register2.php.
**********************************************************************/
?>
<!DOCTYPE html>
<html>
<head>
<title>Frosh IMs</title>
</head>
<body>
<div style="text-align: center;">
<h1>Register for Frosh IMs</h1>
<br><br>
<form action="register2.php" method="post">
<table style="border: 0; margin-left: auto; margin-right: auto; text-align: left">
<tr>
<td>Name:</td>
<td><input name="name" type="text"></td>
</tr>
<tr>
<td>Captain:</td>
<td><input name="captain" type="checkbox"></td>
</tr>
<tr>
<td>Gender:</td>
<td>
<input name="gender" type="radio" value="F"> F
<input name="gender" type="radio" value="M"> M
</td>
</tr>
<tr>
<td>Dorm:</td>
<td>
<select name="dorm">
<option value=""></option>
<option value="Apley Court">Apley Court</option>
<option value="Canaday">Canaday</option>
<option value="Grays">Grays</option>
<option value="Greenough">Greenough</option>

lectures/2/src/froshims/froshims2.php
49.
<option value="Hollis">Hollis</option>
50.
<option value="Holworthy">Holworthy</option>
51.
<option value="Hurlbut">Hurlbut</option>
52.
<option value="Lionel">Lionel</option>
53.
<option value="Matthews">Matthews</option>
54.
<option value="Mower">Mower</option>
55.
<option value="Pennypacker">Pennypacker</option>
56.
<option value="Stoughton">Stoughton</option>
57.
<option value="Straus">Straus</option>
58.
<option value="Thayer">Thayer</option>
59.
<option value="Weld">Weld</option>
60.
<option value="Wigglesworth">Wigglesworth</option>
61.
</select>
62.
</td>
63.
</tr>
64.
</table>
65.
<br><br>
66.
<input type="submit" value="Register!">
67.
</form>
68.
</div>
69.
</body>
70. </html>

lectures/2/src/froshims/froshims3.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.

<?
/***********************************************************************
* froshims3.php
*
* David J. Malan
* malan@harvard.edu
*
* Implements a registration form for Frosh IMs.
* Submits to register3.php.
**********************************************************************/
?>
<!DOCTYPE html>
<html>
<head>
<title>Frosh IMs</title>
</head>
<body>
<div style="text-align: center">
<h1>Register for Frosh IMs</h1>
<br><br>
<form action="register3.php" method="post">
<table style="border: 0; margin-left: auto; margin-right: auto; text-align: left">
<tr>
<td>Name:</td>
<td><input name="name" type="text"></td>
</tr>
<tr>
<td>Captain:</td>
<td><input name="captain" type="checkbox"></td>
</tr>
<tr>
<td>Gender:</td>
<td>
<input name="gender" type="radio" value="F"> F
<input name="gender" type="radio" value="M"> M
</td>
</tr>
<tr>
<td>Dorm:</td>
<td>
<select name="dorm">
<option value=""></option>
<option value="Apley Court">Apley Court</option>
<option value="Canaday">Canaday</option>
<option value="Grays">Grays</option>
<option value="Greenough">Greenough</option>

lectures/2/src/froshims/froshims3.php
49.
<option value="Hollis">Hollis</option>
50.
<option value="Holworthy">Holworthy</option>
51.
<option value="Hurlbut">Hurlbut</option>
52.
<option value="Lionel">Lionel</option>
53.
<option value="Matthews">Matthews</option>
54.
<option value="Mower">Mower</option>
55.
<option value="Pennypacker">Pennypacker</option>
56.
<option value="Stoughton">Stoughton</option>
57.
<option value="Straus">Straus</option>
58.
<option value="Thayer">Thayer</option>
59.
<option value="Weld">Weld</option>
60.
<option value="Wigglesworth">Wigglesworth</option>
61.
</select>
62.
</td>
63.
</tr>
64.
</table>
65.
<br><br>
66.
<input type="submit" value="Register!" />
67.
</form>
68.
</div>
69.
</body>
70. </html>

lectures/2/src/froshims/froshims4.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.

<?
/***********************************************************************
* froshims4.php
*
* David J. Malan
* malan@harvard.edu
*
* Implements a registration form for Frosh IMs. Submits to itself.
**********************************************************************/
// if form was actually submitted, check for error
if (isset($_POST["action"]))
{
if (empty($_POST["name"]) || empty($_POST["gender"]) || empty($_POST["dorm"]))
$error = true;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Frosh IMs</title>
</head>
<body>
<div style="text-align: center">
<h1>Register for Frosh IMs</h1>
<? if (isset($error)): ?>
<div style="color: red">You must fill out the form!</div>
<? endif ?>
<br><br>
<form action="froshims4.php" method="post">
<table style="border: 0; margin-left: auto; margin-right: auto; text-align: left">
<tr>
<td>Name:</td>
<td><input name="name" type="text"></td>
</tr>
<tr>
<td>Captain:</td>
<td><input name="captain" type="checkbox"></td>
</tr>
<tr>
<td>Gender:</td>
<td>
<input name="gender" type="radio" value="F"> F
<input name="gender" type="radio" value="M"> M
</td>
</tr>

lectures/2/src/froshims/froshims4.php
49.
<tr>
50.
<td>Dorm:</td>
51.
<td>
52.
<select name="dorm">
53.
<option value=""></option>
54.
<option value="Apley Court">Apley Court</option>
55.
<option value="Canaday">Canaday</option>
56.
<option value="Grays">Grays</option>
57.
<option value="Greenough">Greenough</option>
58.
<option value="Hollis">Hollis</option>
59.
<option value="Holworthy">Holworthy</option>
60.
<option value="Hurlbut">Hurlbut</option>
61.
<option value="Lionel">Lionel</option>
62.
<option value="Matthews">Matthews</option>
63.
<option value="Mower">Mower</option>
64.
<option value="Pennypacker">Pennypacker</option>
65.
<option value="Stoughton">Stoughton</option>
66.
<option value="Straus">Straus</option>
67.
<option value="Thayer">Thayer</option>
68.
<option value="Weld">Weld</option>
69.
<option value="Wigglesworth">Wigglesworth</option>
70.
</select>
71.
</td>
72.
</tr>
73.
</table>
74.
<br><br>
75.
<input name="action" type="submit" value="Register!">
76.
</form>
77.
</div>
78.
</body>
79. </html>

lectures/2/src/froshims/froshims5.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.

<?
/***********************************************************************
* froshims5.php
*
* David J. Malan
* malan@harvard.edu
*
* Implements a registration form for Frosh IMs. Submits to itself.
* Pre-populates name field upon error.
**********************************************************************/
// if form was actually submitted, check for error
if (isset($_POST["action"]))
{
if (empty($_POST["name"]) || empty($_POST["gender"]) || empty($_POST["dorm"]))
$error = true;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Frosh IMs</title>
</head>
<body>
<div style="text-align: center">
<h1>Register for Frosh IMs</h1>
<? if (isset($error)): ?>
<div style="color: red">You must fill out the form!</div>
<? endif ?>
<br><br>
<form action="froshims5.php" method="post">
<table style="border: 0; margin-left: auto; margin-right: auto; text-align: left">
<tr>
<td>Name:</td>
<td><input name="name" type="text" value="<? if (isset($_POST["name"])) echo htmlspecialchars($_POST["name"]) ?>"></td>
</tr>
<tr>
<td>Captain:</td>
<td><input name="captain" type="checkbox"></td>
</tr>
<tr>
<td>Gender:</td>
<td>
<input name="gender" type="radio" value="F"> F
<input name="gender" type="radio" value="M"> M
</td>

lectures/2/src/froshims/froshims5.php
49.
</tr>
50.
<tr>
51.
<td>Dorm:</td>
52.
<td>
53.
<select name="dorm">
54.
<option value=""></option>
55.
<option value="Apley Court">Apley Court</option>
56.
<option value="Canaday">Canaday</option>
57.
<option value="Grays">Grays</option>
58.
<option value="Greenough">Greenough</option>
59.
<option value="Hollis">Hollis</option>
60.
<option value="Holworthy">Holworthy</option>
61.
<option value="Hurlbut">Hurlbut</option>
62.
<option value="Lionel">Lionel</option>
63.
<option value="Matthews">Matthews</option>
64.
<option value="Mower">Mower</option>
65.
<option value="Pennypacker">Pennypacker</option>
66.
<option value="Stoughton">Stoughton</option>
67.
<option value="Straus">Straus</option>
68.
<option value="Thayer">Thayer</option>
69.
<option value="Weld">Weld</option>
70.
<option value="Wigglesworth">Wigglesworth</option>
71.
</select>
72.
</td>
73.
</tr>
74.
</table>
75.
<br><br>
76.
<input name="action" type="submit" value="Register!">
77.
</form>
78.
</div>
79.
</body>
80. </html>

lectures/2/src/froshims/froshims6.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.

<?
/***********************************************************************
* froshims6.php
*
* David J. Malan
* malan@harvard.edu
*
* Implements a registration form for Frosh IMs. Submits to itself.
* Generates list of dorms via an array.
**********************************************************************/
// array of dorms
$DORMS = array(
"Apley Court",
"Canaday",
"Grays",
"Greenough",
"Hollis",
"Holworthy",
"Hurlbut",
"Lionel",
"Matthews",
"Mower",
"Pennypacker",
"Stoughton",
"Straus",
"Thayer",
"Weld",
"Wigglesworth"
);
// if form was actually submitted, check for error
if (isset($_POST["action"]))
{
if (empty($_POST["name"]) || empty($_POST["gender"]) || empty($_POST["dorm"]))
$error = true;
}
?>

<!DOCTYPE html>
<html>
<head>
<title>Frosh IMs</title>
</head>
<body>
<div align="center">

lectures/2/src/froshims/froshims6.php
49.
<h1>Register for Frosh IMs</h1>
50.
<? if (isset($error)): ?>
51.
<div style="color: red;">You must fill out the form!</div>
52.
<? endif ?>
53.
<br><br>
54.
<form action="froshims6.php" method="post">
55.
<table style="border: 0; margin-left: auto; margin-right: auto; text-align: left">
56.
<tr>
57.
<td>Name:</td>
58.
<td><input name="name" type="text" value="<? if (isset($_POST["name"])) echo htmlspecialchars($_POST["name"]) ?>"></td>
59.
</tr>
60.
<tr>
61.
<td>Captain:</td>
62.
<td><input name="captain" type="checkbox"></td>
63.
</tr>
64.
<tr>
65.
<td>Gender:</td>
66.
<td>
67.
<input name="gender" type="radio" value="F"> F
68.
<input name="gender" type="radio" value="M"> M
69.
</td>
70.
</tr>
71.
<tr>
72.
<td>Dorm:</td>
73.
<td>
74.
<select name="dorm">
75.
<option value=""></option>
76.
<? foreach ($DORMS as $dorm): ?>
77.
<option value="<?= $dorm ?>"><?= $dorm ?></option>
78.
<? endforeach ?>
79.
</select>
80.
</td>
81.
</tr>
82.
</table>
83.
<br><br>
84.
<input name="action" type="submit" value="Register!">
85.
</form>
86.
</div>
87.
</body>
88. </html>

lectures/2/src/froshims/froshims7.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.

<?
/***********************************************************************
* froshims7.php
*
* David J. Malan
* malan@harvard.edu
*
* Implements a registration form for Frosh IMs. Submits to itself.
* Generates list of dorms via an array. Pre-populates name and
* dorm fields upon error.
**********************************************************************/
// array of dorms
$DORMS = array(
"Apley Court",
"Canaday",
"Grays",
"Greenough",
"Hollis",
"Holworthy",
"Hurlbut",
"Lionel",
"Matthews",
"Mower",
"Pennypacker",
"Stoughton",
"Straus",
"Thayer",
"Weld",
"Wigglesworth"
);
// if form was actually submitted, check for error
if (isset($_POST["action"]))
{
if (empty($_POST["name"]) || empty($_POST["gender"]) || empty($_POST["dorm"]))
$error = true;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Frosh IMs</title>
</head>
<body>
<div style="text-align: center">

lectures/2/src/froshims/froshims7.php
49.
<h1>Register for Frosh IMs</h1>
50.
<? if (isset($error)): ?>
51.
<div style="color: red;">You must fill out the form!</div>
52.
<? endif ?>
53.
<br><br>
54.
<form action="froshims7.php" method="post">
55.
<table style="border: 0; margin-left: auto; margin-right: auto; text-align: left">
56.
<tr>
57.
<td>Name:</td>
58.
<td><input name="name" type="text" value="<? if (isset($_POST["name"])) echo htmlspecialchars($_POST["name"]) ?>"></td>
59.
</tr>
60.
<tr>
61.
<td>Captain:</td>
62.
<td><input name="captain" type="checkbox"></td>
63.
</tr>
64.
<tr>
65.
<td>Gender:</td>
66.
<td>
67.
<input name="gender" type="radio" value="F"> F
68.
<input name="gender" type="radio" value="M"> M
69.
</td>
70.
</tr>
71.
<tr>
72.
<td>Dorm:</td>
73.
<td>
74.
<select name="dorm">
75.
<option value=""></option>
76.
<?
77.
foreach ($DORMS as $dorm)
78.
{
79.
if (isset($_POST["dorm"]) && $_POST["dorm"] == $dorm)
80.
echo "<option selected='selected' value='$dorm'>$dorm</option>";
81.
else
82.
echo "<option value='$dorm'>$dorm</option>";
83.
}
84.
?>
85.
</select>
86.
</td>
87.
</tr>
88.
</table>
89.
<br><br>
90.
<input name="action" type="submit" value="Register!">
91.
</form>
92.
</div>
93.
</body>
94. </html>

lectures/2/src/froshims/froshims8.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.

<?
/***********************************************************************
* froshims8.php
*
* David J. Malan
* malan@harvard.edu
*
* Implements a registration form for Frosh IMs. Submits to
* register8.php.
**********************************************************************/
?>
<!DOCTYPE html>
<html>
<head>
<title>Frosh IMs</title>
</head>
<body>
<div style="text-align: center">
<h1>Register for Frosh IMs</h1>
<br><br>
<form action="register8.php" method="post">
<table style="border: 0; margin-left: auto; margin-right: auto; text-align: left">
<tr>
<td>Name:</td>
<td><input name="name" type="text"></td>
</tr>
<tr>
<td>Captain:</td>
<td><input name="captain" type="checkbox"></td>
</tr>
<tr>
<td>Gender:</td>
<td>
<input name="gender" type="radio" value="F"> F
<input name="gender" type="radio" value="M"> M
</td>
</tr>
<tr>
<td>Dorm:</td>
<td>
<select name="dorm">
<option value=""></option>
<option value="Apley Court">Apley Court</option>
<option value="Canaday">Canaday</option>
<option value="Grays">Grays</option>
<option value="Greenough">Greenough</option>

lectures/2/src/froshims/froshims8.php
49.
<option value="Hollis">Hollis</option>
50.
<option value="Holworthy">Holworthy</option>
51.
<option value="Hurlbut">Hurlbut</option>
52.
<option value="Lionel">Lionel</option>
53.
<option value="Matthews">Matthews</option>
54.
<option value="Mower">Mower</option>
55.
<option value="Pennypacker">Pennypacker</option>
56.
<option value="Stoughton">Stoughton</option>
57.
<option value="Straus">Straus</option>
58.
<option value="Thayer">Thayer</option>
59.
<option value="Weld">Weld</option>
60.
<option value="Wigglesworth">Wigglesworth</option>
61.
</select>
62.
</td>
63.
</tr>
64.
</table>
65.
<br><br>
66.
<input type="submit" value="Register!">
67.
</form>
68.
</div>
69.
</body>
70. </html>

lectures/2/src/froshims/register0.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.

<?
/***************************************************************
* register0.php
*
* Computer Science 50
* David J. Malan
*
* Dumps contents of $_POST.
***************************************************************/
?>
<!DOCTYPE html>
<html>
<head>
<title>Frosh IMs</title>
</head>
<body>
<pre>
<? print_r($_POST); ?>
</pre>
</body>
</html>

lectures/2/src/froshims/register1.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.

<?
/***************************************************************
* register1.php
*
* Computer Science 50
* David J. Malan
*
* Implements a registration form for Frosh IMs. Redirects
* user to froshims1.php upon error.
***************************************************************/
// validate submission
if (empty($_POST["name"]) || empty($_POST["gender"]) || empty($_POST["dorm"]))
{
header("Location: http://localhost/~jharvard/froshims/froshims1.php");
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Frosh IMs</title>
</head>
<body>
You are registered! (Well, not really.)
</body>
</html>

lectures/2/src/froshims/register2.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.

<?
/***********************************************************************
* register2.php
*
* Computer Science 50
* David J. Malan
*
* Implements a registration form for Frosh IMs. Informs user of
* any errors.
**********************************************************************/
?>
<!DOCTYPE html>
<html>
<head>
<title>Frosh IMs</title>
</head>
<body>
<? if (empty($_POST["name"]) || empty($_POST["gender"]) || empty($_POST["dorm"]): ?>
You must provide your name, gender, and dorm! Go <a href="froshims2.php">back</a>.
<? else: ?>
You are registered! (Well, not really.)
<? endif ?>
</body>
</html>

lectures/2/src/froshims/register3.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.

<?
/***********************************************************************
* register3.php
*
* Computer Science 50
* David J. Malan
*
* Implements a registration form for Frosh IMs. Reports registration
* via email. Redirects user to froshims3.php upon error.
**********************************************************************/
// validate submission
if (!empty($_POST["name"]) && !empty($_POST["gender"]) && !empty($_POST["dorm"]))
{
$to = "malan@cs50.net";
$subject = "Registration";
$body = "This person just registered:\n\n" .
$_POST["name"] . "\n" .
$_POST["captain"] . "\n" .
$_POST["gender"] . "\n" .
$_POST["dorm"];
$headers = "From: malan@cs50.net\r\n";
mail($to, $subject, $body, $headers);
}
else
{
header("Location: http://localhost/~jharvard/froshims/froshims3.php");
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Frosh IMs</title>
</head>
<body>
You are registered! (Really.)
</body>
</html>

lectures/2/src/froshims/register8.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.

<?
/***********************************************************************
* register8.php
*
* Computer Science 50
* David J. Malan
*
* Implements a registration form for Frosh IMs. Records registration
* in database. Redirects user to froshims8.php upon error.
**********************************************************************/
// validate submission
if (empty($_POST["name"]) || empty($_POST["gender"]) || empty($_POST["dorm"]))
{
header("Location: http://localhost/~jharvard/froshims/froshims8.php");
exit;
}
// connect to database
mysql_connect("localhost", "jharvard", "crimson");
mysql_select_db("jharvard_froshims");
// scrub inputs
$name = mysql_real_escape_string($_POST["name"]);
if ($_POST["captain"])
$captain = 1;
else
$captain = 0;
$gender = mysql_real_escape_string($_POST["gender"]);
$dorm = mysql_real_escape_string($_POST["dorm"]);
// prepare query
$sql = "INSERT INTO registrants (name, captain, gender, dorm)
VALUES('$name', $captain, '$gender', '$dorm')";
// execute query
mysql_query($sql);
?>
<!DOCTYPE html>
<html>
<head>
<title>Frosh IMs</title>
</head>
<body>
You are registered! (Really.)
</body>

lectures/2/src/froshims/register8.php
49. </html>

lectures/2/src/froshims/registrants.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.

<?
// connect to database
mysql_connect("localhost", "jharvard", "crimson");
mysql_select_db("jharvard_froshims");
// prepare query
$sql = "SELECT * FROM registrants";
// execute query
$result = mysql_query($sql);
?>
<!DOCTYPE html>
<html>
<head>
<title>Frosh IMs</title>
</head>
<body>
<ul>
<?
// iterate over results
while ($row = mysql_fetch_array($result))
{
print("<li>");
print(htmlspecialchars($row["name"]));
print("</li>");
}
?>
</ul>
</body>
</html>

lectures/2/src/login/home.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.

<?
/**
* home.php
*
* A simple home page for these login demos.
*
* David J. Malan
* malan@harvard.edu
*/
// enable sessions
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>Home</title>
</head>
<body>
<h1>Home</h1>
<h3>
<? if (isset($_SESSION["authenticated"]) && $_SESSION["authenticated"] === true) { ?>
You are logged in!
<br>
<a href="logout.php">log out</a>
<? } else { ?>
You are not logged in!
<? } ?>
</h3>
<br>
<b>Login Demos</b>
<ul>
<li><a href="login1.php">version 1</a></li>
<li><a href="login2.php">version 2</a></li>
<li><a href="login3.php">version 3</a></li>
<li><a href="login4.php">version 4</a></li>
</ul>
</body>
</html>

lectures/2/src/login/login1.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.

<?
/**
* login1.php
*
* A simple login module.
*
* David J. Malan
* malan@harvard.edu
*/
// enable sessions
session_start();
// were this not a demo, these would be in some database
define("USER", "jharvard");
define("PASS", "crimson");
// if username and password were submitted, check them
if (isset($_POST["user"]) && isset($_POST["pass"]))
{
// if username and password are valid, log user in
if ($_POST["user"] == USER && $_POST["pass"] == PASS)
{
// remember that user's logged in
$_SESSION["authenticated"] = true;
// redirect user to home page, using absolute path, per
// http://us2.php.net/manual/en/function.header.php
$host = $_SERVER["HTTP_HOST"];
$path = rtrim(dirname($_SERVER["PHP_SELF"]), "/\\");
header("Location: http://$host$path/home.php");
exit;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Log In</title>
</head>
<body>
<? if (count($_POST) > 0) echo "INVALID LOGIN"; ?>
<form action="<?= $_SERVER["PHP_SELF"] ?>" method="post">
<table>
<tr>
<td>Username:</td>

lectures/2/src/login/login1.php
49.
<td><input name="user" type="text"></td>
50.
</tr>
51.
<tr>
52.
<td>Password:</td>
53.
<td><input name="pass" type="password"></td>
54.
</tr>
55.
<tr>
56.
<td></td>
57.
<td><input type="submit" value="Log In"></td>
58.
</tr>
59.
</table>
60.
</form>
61.
</body>
62. </html>

lectures/2/src/login/login2.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.

<?
/**
* login2.php
*
* A simple login module that pre-populates the username field
* upon failed login, just in case user simply mistyped password.
*
* David J. Malan
* malan@harvard.edu
*/
// enable sessions
session_start();
// were this not a demo, these would be in some database
define("USER", "jharvard");
define("PASS", "crimson");
// if username and password were submitted, check them
if (isset($_POST["user"]) && isset($_POST["pass"]))
{
// if username and password are valid, log user in
if ($_POST["user"] == USER && $_POST["pass"] == PASS)
{
// remember that user's logged in
$_SESSION["authenticated"] = true;
// redirect user to home page, using absolute path, per
// http://us2.php.net/manual/en/function.header.php
$host = $_SERVER["HTTP_HOST"];
$path = rtrim(dirname($_SERVER["PHP_SELF"]), "/\\");
header("Location: http://$host$path/home.php");
exit;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Log In</title>
</head>
<body>
<form action="<?- $_SERVER["PHP_SELF"] ?>" method="post">
<table>
<tr>
<td>Username:</td>

lectures/2/src/login/login2.php
49.
<td><input name="user" type="text" value="<? if (isset($_POST["user"])) echo htmlspecialchars($_POST["user"]) ?>"></td>
50.
</tr>
51.
<tr>
52.
<td>Password:</td>
53.
<td><input name="pass" type="password"></td>
54.
</tr>
55.
<tr>
56.
<td></td>
57.
<td><input type="submit" value="Log In"></td>
58.
</tr>
59.
</table>
60.
</form>
61.
</body>
62. </html>

lectures/2/src/login/login3.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.

<?
/**
* login3.php
*
* A simple login module that remembers username of most recently
* authenticated user so that it can pre-populate the username
* field next time.
*
* David J. Malan
* malan@harvard.edu
*/
// enable sessions
session_start();
// were this not a demo, these would be in some database
define("USER", "jharvard");
define("PASS", "crimson");
// if username and password were submitted, check them
if (isset($_POST["user"]) && isset($_POST["pass"]))
{
// if username and password are valid, log user in
if ($_POST["user"] == USER && $_POST["pass"] == PASS)
{
// remember that user's logged in
$_SESSION["authenticated"] = true;
// save username in cookie for a week
setcookie("user", $_POST["user"], time() + 7 * 24 * 60 * 60);
// redirect user to home page, using absolute path, per
// http://us2.php.net/manual/en/function.header.php
$host = $_SERVER["HTTP_HOST"];
$path = rtrim(dirname($_SERVER["PHP_SELF"]), "/\\");
header("Location: http://$host$path/home.php");
exit;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Log In</title>
</head>
<body>

lectures/2/src/login/login3.php
49.
<form action="<?= $_SERVER["PHP_SELF"] ?>" method="post">
50.
<table>
51.
<tr>
52.
<td>Username:</td>
53.
<td>
54.
<? if (isset($_POST["user"])): ?>
55.
<input name="user" type="text" value="<?= htmlspecialchars($_POST["user"]) ?>">
56.
<? elseif (isset($_COOKIE["user"])): ?>
57.
<input name="user" type="text" value="<?= htmlspecialchars($_COOKIE["user"]) ?>">
58.
<? else: ?>
59.
<input name="user" type="text" value="">
60.
<? endif ?>
61.
</tr>
62.
<tr>
63.
<td>Password:</td>
64.
<td><input name="pass" type="password"></td>
65.
</tr>
66.
<tr>
67.
<td></td>
68.
<td><input type="submit" value="Log In"></td>
69.
</tr>
70.
</table>
71.
</form>
72.
</body>
73. </html>

lectures/2/src/login/login4.php
1. <?
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.

/**
* login4.php
*
* A simple login module that lets a user stay logged in
* by saving username and, ack, password in cookies.
*
* David J. Malan
* malan@harvard.edu
*/
// enable sessions
session_start();
// were this not a demo, these would be in some database
define("USER", "jharvard");
define("PASS", "crimson");
// if username and password were saved in cookie, check them
if (isset($_COOKIE["user"]) && isset($_COOKIE["pass"]))
{
// if username and password are valid, log user back in
if ($_COOKIE["user"] == USER && $_COOKIE["pass"] == PASS)
{
// remember that user's logged in
$_SESSION["authenticated"] = true;
// re-save username and, ack, password in cookies for another week
setcookie("user", $_COOKIE["user"], time() + 7 * 24 * 60 * 60);
setcookie("pass", $_COOKIE["pass"], time() + 7 * 24 * 60 * 60);
// redirect user to home page, using absolute path, per
// http://us2.php.net/manual/en/function.header.php
$host = $_SERVER["HTTP_HOST"];
$path = rtrim(dirname($_SERVER["PHP_SELF"]), "/\\");
header("Location: http://$host$path/home.php");
exit;
}
}
// else if username and password were submitted, grab them instead
else if (isset($_POST["user"]) && isset($_POST["pass"]))
{
// if username and password are valid, log user in
if ($_POST["user"] == USER && $_POST["pass"] == PASS)
{
// remember that user's logged in
$_SESSION["authenticated"] = true;

lectures/2/src/login/login4.php
49.
50.
// save username in cookie for a week
51.
setcookie("user", $_POST["user"], time() + 7 * 24 * 60 * 60);
52.
53.
// save password in, ack, cookie for a week if requested
54.
if ($_POST["keep"])
55.
setcookie("pass", $_POST["pass"], time() + 7 * 24 * 60 * 60);
56.
57.
// redirect user to home page, using absolute path, per
58.
// http://us2.php.net/manual/en/function.header.php
59.
$host = $_SERVER['HTTP_HOST'];
60.
$path = rtrim(dirname($_SERVER["PHP_SELF"]), "/\\");
61.
header("Location: http://$host$path/home.php");
62.
exit;
63.
}
64.
}
65. ?>
66.
67. <!DOCTYPE html>
68.
69. <html>
70.
<head>
71.
<title>Log In</title>
72.
</head>
73.
<body>
74.
<form action="<?= $_SERVER["PHP_SELF"] ?>" method="post">
75.
<table>
76.
<tr>
77.
<td>Username:</td>
78.
<td>
79.
<? if (isset($_POST["user"])): ?>
80.
<input name="user" type="text" value="<?= htmlspecialchars($_POST["user"]) ?>">
81.
<? elseif (isset($_COOKIE["user"])): ?>
82.
<input name="user" type="text" value="<?= htmlspecialchars($_COOKIE["user"]) ?>">
83.
<? else: ?>
84.
<input name="user" type="text" value="">
85.
<? endif ?>
86.
</td>
87.
</tr>
88.
<tr>
89.
<td>Password:</td>
90.
<td><input name="pass" type="password"></td>
91.
</tr>
92.
<tr>
93.
<td></td>
94.
<td><input name="keep" type="checkbox"> &nbsp; keep me logged in until I click <b>log out</b></td>
95.
</tr>
96.
<tr>

lectures/2/src/login/login4.php
97.
<td></td>
98.
<td><input type="submit" value="Log In"></td>
99.
</tr>
100.
</table>
101.
</form>
102.
</body>
103. </html>

lectures/2/src/login/logout.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.

<?
/**
* logout.php
*
* A simple logout module for all of our login modules.
*
* David J. Malan
* malan@harvard.edu
*/
// enable sessions
session_start();
// delete cookies, if any
setcookie("user", "", time() - 3600);
setcookie("pass", "", time() - 3600);
// log user out
setcookie(session_name(), "", time() - 3600);
session_destroy();
?>
<!DOCTYPE html>
<html>
<head>
<title>Log Out</title>
</head>
<body>
<h1>You are logged out!</h1>
<h3><a href="home.php">home</a></h3>
</body>
</html>

lectures/2/src/mvc/0/index.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.

<!-index.php
David J. Malan
malan@harvard.edu
A homepage for the course.
-->
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width">
<title>CSCI S-75</title>
</head>
<body>
<h1>CSCI S-75</h1>
<ul>
<li><a href="lectures.php">Lectures</a></li>
<li><a href="http://cdn.cs75.net/2012/summer/lectures/0/syllabus.pdf">Syllabus</a></li>
</ul>
</body>
</html>

lectures/2/src/mvc/0/lecture0.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.

<!-lecture0.php
David J. Malan
malan@harvard.edu
Represents a lecture.
-->
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width">
<title>Lecture 0</title>
</head>
<body>
<h1>Lecture 0</h1>
<ul>
<li><a href="http://cdn.cs75.net/2012/summer/lectures/0/slides0.pdf">Slides</a></li>
<li><a href="http://cdn.cs75.net/2012/summer/lectures/0/lecture0.mp4">Video</a></li>
</ul>
</body>
</html>

lectures/2/src/mvc/0/lecture1.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.

<!-lecture1.php
David J. Malan
malan@harvard.edu
Represents a lecture.
-->
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width">
<title>Lecture 1</title>
</head>
<body>
<h1>Lecture 1</h1>
<ul>
<li><a href="http://cdn.cs75.net/2012/summer/lectures/1/slides1.pdf">Slides</a></li>
<li><a href="http://cdn.cs75.net/2012/summer/lectures/1/lecture1.mp4">Video</a></li>
</ul>
</body>
</html>

lectures/2/src/mvc/0/lectures.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.

<!-lectures.php
David J. Malan
malan@harvard.edu
Links to lectures.
-->
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width">
<title>Lectures</title>
</head>
<body>
<h1>Lectures</h1>
<ul>
<li><a href="lecture0.php">Lecture 0</a></li>
<li><a href="lecture1.php">Lecture 1</a></li>
</ul>
</body>
</html>

lectures/2/src/mvc/1/footer.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.

<?php /*
footer.php
David J. Malan
malan@harvard.edu
A footer for pages.
*/ ?>
</body>
</html>

lectures/2/src/mvc/1/header.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.

<?php /*
header.php
David J. Malan
malan@harvard.edu
A header for pages.
*/ ?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width">
<title>CSCI S-75</title>
</head>
<body>
<h1>CSCI S-75</h1>

lectures/2/src/mvc/1/index.php
1.
2.
3.
4.
5.
6.
7.
8.

<?php require('header.php'); ?>


<ul>
<li><a href="lectures.php">Lectures</a></li>
<li><a href="http://cdn.cs75.net/2012/summer/lectures/0/syllabus.pdf">Syllabus</a></li>
</ul>
<?php require('footer.php'); ?>

lectures/2/src/mvc/1/lecture0.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.

<?php /*
lecture0.php
David J. Malan
malan@harvard.edu
Represents a lecture.
*/ ?>
<?php require('header.php'); ?>
<ul>
<li><a href="http://cdn.cs75.net/2012/summer/lectures/0/slides0.pdf">Slides</a></li>
<li><a href="http://cdn.cs75.net/2012/summer/lectures/0/lecture0.mp4">Video</a></li>
</ul>
<?php require('footer.php'); ?>

lectures/2/src/mvc/1/lecture1.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.

<?php /*
lecture1.php
David J. Malan
malan@harvard.edu
Represents a lecture.
*/ ?>
<?php require('header.php'); ?>
<ul>
<li><a href="http://cdn.cs75.net/2012/summer/lectures/1/slides1.pdf">Slides</a></li>
<li><a href="http://cdn.cs75.net/2012/summer/lectures/1/lecture1.mp4">Video</a></li>
</ul>
<?php require('footer.php'); ?>

lectures/2/src/mvc/1/lectures.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.

<?php /*
lectures.php
David J. Malan
malan@harvard.edu
Links to lectures.
*/ ?>
<?php require('header.php'); ?>
<ul>
<li><a href="lecture0.php">Lecture 0</a></li>
<li><a href="lecture1.php">Lecture 1</a></li>
</ul>
<?php require('footer.php'); ?>

lectures/2/src/mvc/1/README
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.

mvc/1/README
David J. Malan
malan@harvard.edu
Improves upon mvc/0 by factoring out pages' header and footer.
footer.php - pages' footer
header.php - pages' header
index.php - homepage for the course
lecture0.php - a lecture
lecture1.php - a lecture
lectures.php - a list of lectures

lectures/2/src/mvc/2/footer.php
1.
</body>
2. </html>

lectures/2/src/mvc/2/header.php
1. <!DOCTYPE html>
2.
3. <html>
4.
<head>
5.
<meta name="viewport" content="width=device-width">
6.
<title><?php echo htmlspecialchars($title) ?></title>
7.
</head>
8.
<body>
9.
<h1><?php echo htmlspecialchars($title) ?></h1>

lectures/2/src/mvc/2/helpers.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.

<?php
/**
* Renders footer.
*
* @param array $data
*/
function renderFooter($data = array())
{
extract($data);
require('footer.php');
}
/**
* Renders header.
*
* @param array $data
*/
function renderHeader($data = array())
{
extract($data);
require('header.php');
}
?>

lectures/2/src/mvc/2/index.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.

<?php
require_once('helpers.php');
?>

<?php renderHeader(array('title' => 'CSCI S-75')); ?>


<ul>
<li><a href="lectures.php">Lectures</a></li>
<li><a href="http://cdn.cs75.net/2012/summer/lectures/0/syllabus.pdf">Syllabus</a></li>
</ul>
<?php renderFooter(); ?>

lectures/2/src/mvc/2/lecture0.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.

<?php
require_once('helpers.php');
?>
<?php renderHeader(array('title' => 'Lecture 0')); ?>
<ul>
<li><a href="http://cdn.cs75.net/2012/summer/lectures/0/slides0.pdf">Slides</a></li>
<li><a href="http://cdn.cs75.net/2012/summer/lectures/0/lecture0.mp4">Video</a></li>
</ul>
<?php renderFooter(); ?>

lectures/2/src/mvc/2/lecture1.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.

<?php
require_once('helpers.php');
?>
<?php renderHeader(array('title' => 'Lecture 1')); ?>
<ul>
<li><a href="http://cdn.cs75.net/2012/summer/lectures/1/slides1.pdf">Slides</a></li>
<li><a href="http://cdn.cs75.net/2012/summer/lectures/1/lecture1.mp4">Video</a></li>
</ul>
<?php renderFooter(); ?>

lectures/2/src/mvc/2/lectures.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.

<?php
require_once('helpers.php');
?>
<?php renderHeader(array('title' => 'Lectures')); ?>
<ul>
<li><a href="lecture0.php">Lecture 0</a></li>
<li><a href="lecture1.php">Lecture 1</a></li>
</ul>
<?php renderFooter(); ?>

lectures/2/src/mvc/2/README
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.

mvc/2/README
David J. Malan
malan@harvard.edu
Improves upon mvc/1 by wrapping header and footer with a parameterized function.
footer.php - pages' footer
header.php - pages' header
helpers.php - helper functions
index.php - homepage for the course
lecture0.php - a lecture
lecture1.php - a lecture
lectures.php - a list of lectures

lectures/2/src/mvc/3/footer.php
1.
</body>
2. </html>

lectures/2/src/mvc/3/header.php
1. <!DOCTYPE html>
2.
3. <html>
4.
<head>
5.
<meta name="viewport" content="width=device-width">
6.
<title><?php echo htmlspecialchars($title) ?></title>
7.
</head>
8.
<body>
9.
<h1><?php echo htmlspecialchars($title) ?></h1>

lectures/2/src/mvc/3/helpers.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.

<?php
/**
* Renders template.
*
* @param array $data
*/
function render($template, $data = array())
{
$path = $template . '.php';
if (file_exists($path))
{
extract($data);
require($path);
}
}
?>

lectures/2/src/mvc/3/index.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.

<?php
require_once('helpers.php');
?>

<?php render('header', array('title' => 'CSCI S-75')); ?>


<ul>
<li><a href="lectures.php">Lectures</a></li>
<li><a href="http://cdn.cs75.net/2012/summer/lectures/0/syllabus.pdf">Syllabus</a></li>
</ul>
<?php render('footer'); ?>

lectures/2/src/mvc/3/lecture0.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.

<?php
require_once('helpers.php');
?>
<?php render('header', array('title' => 'Lecture 0')); ?>
<ul>
<li><a href="http://cdn.cs75.net/2012/summer/lectures/0/slides0.pdf">Slides</a></li>
<li><a href="http://cdn.cs75.net/2012/summer/lectures/0/lecture0.mp4">Video</a></li>
</ul>
<?php render('footer'); ?>

lectures/2/src/mvc/3/lecture1.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.

<?php
require_once('helpers.php');
?>
<?php render('header', array('title' => 'Lecture 1')); ?>
<ul>
<li><a href="http://cdn.cs75.net/2012/summer/lectures/1/slides1.pdf">Slides</a></li>
<li><a href="http://cdn.cs75.net/2012/summer/lectures/1/lecture1.mp4">Video</a></li>
</ul>
<?php render('footer'); ?>

lectures/2/src/mvc/3/lectures.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.

<?php
require_once('helpers.php');
?>
<?php render('header', array('title' => 'Lectures')); ?>
<ul>
<li><a href="lecture0.php">Lecture 0</a></li>
<li><a href="lecture1.php">Lecture 1</a></li>
</ul>
<?php render('footer'); ?>

lectures/2/src/mvc/3/README
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.

mvc/3/README
David J. Malan
malan@harvard.edu
Improves upon mvc/2 by generalizing header and footer as templates.
footer.php - pages' footer
header.php - pages' header
helpers.php - helper functions
index.php - homepage for the course
lecture0.php - a lecture
lecture1.php - a lecture
lectures.php - a list of lectures

lectures/2/src/mvc/4/includes/helpers.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.

<?php
/**
* Renders template.
*
* @param array $data
*/
function render($template, $data = array())
{
$path = __DIR__ . '/../templates/' . $template . '.php';
if (file_exists($path))
{
extract($data);
require($path);
}
}
?>

lectures/2/src/mvc/4/index.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.

<?php
require_once('includes/helpers.php');
?>

<?php render('header', array('title' => 'CS164')); ?>


<ul>
<li><a href="lectures.php">Lectures</a></li>
<li><a href="http://cdn.cs164.net/2012/spring/lectures/0/syllabus.pdf">Syllabus</a></li>
</ul>
<?php render('footer'); ?>

lectures/2/src/mvc/4/lecture0.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.

<?php
require_once('includes/helpers.php');
?>
<?php render('header', array('title' => 'Lecture 0')); ?>
<ul>
<li><a href="http://cdn.cs164.net/2012/spring/lectures/0/slides0.pdf">Slides</a></li>
<li><a href="http://cdn.cs164.net/2012/spring/lectures/0/lecture0.mp4">Video</a></li>
</ul>
<?php render('footer'); ?>

lectures/2/src/mvc/4/lecture1.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.

<?php
require_once('includes/helpers.php');
?>
<?php render('header', array('title' => 'Lecture 1')); ?>
<ul>
<li><a href="http://cdn.cs164.net/2012/spring/lectures/1/slides1.pdf">Slides</a></li>
<li><a href="http://cdn.cs164.net/2012/spring/lectures/1/lecture1.mp4">Video</a></li>
</ul>
<?php render('footer'); ?>

lectures/2/src/mvc/4/lectures.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.

<?php
require_once('includes/helpers.php');
?>
<?php render('header', array('title' => 'Lectures')); ?>
<ul>
<li><a href="lecture0.php">Lecture 0</a></li>
<li><a href="lecture1.php">Lecture 1</a></li>
</ul>
<?php render('footer'); ?>

lectures/2/src/mvc/4/README
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.

mvc/4/README
David J. Malan
malan@harvard.edu
Improves upon mvc/3 by organizing files into subdirectories.
includes/
helpers.php - helper functions
index.php - homepage for the course
lecture0.php - a lecture
lecture1.php - a lecture
lectures.php - a list of lectures
templates/
footer.php - pages' footer
header.php - pages' header

lectures/2/src/mvc/4/templates/footer.php
1.
</body>
2. </html>

lectures/2/src/mvc/4/templates/header.php
1. <!DOCTYPE html>
2.
3. <html>
4.
<head>
5.
<meta name="viewport" content="width=device-width">
6.
<title><?php echo htmlspecialchars($title) ?></title>
7.
</head>
8.
<body>
9.
<h1><?php echo htmlspecialchars($title) ?></h1>

lectures/2/src/mvc/5/html/index.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.

<?php
require_once('../includes/helpers.php');
?>

<?php render('header', array('title' => 'CSCI S-75')); ?>


<ul>
<li><a href="lectures.php">Lectures</a></li>
<li><a href="http://cdn.cs75.net/2012/summer/lectures/0/syllabus.pdf">Syllabus</a></li>
</ul>
<?php render('footer'); ?>

lectures/2/src/mvc/5/html/lecture0.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.

<?php
require_once('../includes/helpers.php');
?>
<?php render('header', array('title' => 'Lecture 0')); ?>
<ul>
<li><a href="http://cdn.cs75.net/2012/summer/lectures/0/slides0.pdf">Slides</a></li>
<li><a href="http://cdn.cs75.net/2012/summer/lectures/0/lecture0.mp4">Video</a></li>
</ul>
<?php render('footer'); ?>

lectures/2/src/mvc/5/html/lecture1.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.

<?php
require_once('../includes/helpers.php');
?>
<?php render('header', array('title' => 'Lecture 1')); ?>
<ul>
<li><a href="http://cdn.cs75.net/2012/summer/lectures/1/slides1.pdf">Slides</a></li>
<li><a href="http://cdn.cs75.net/2012/summer/lectures/1/lecture1.mp4">Video</a></li>
</ul>
<?php render('footer'); ?>

lectures/2/src/mvc/5/html/lectures.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.

<?php
require_once('../includes/helpers.php');
?>
<?php render('header', array('title' => 'Lectures')); ?>
<ul>
<li><a href="lecture0.php">Lecture 0</a></li>
<li><a href="lecture1.php">Lecture 1</a></li>
</ul>
<?php render('footer'); ?>

lectures/2/src/mvc/5/includes/helpers.php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.

<?php
/**
* Renders template.
*
* @param array $data
*/
function render($template, $data = array())
{
$path = __DIR__ . '/../templates/' . $template . '.php';
if (file_exists($path))
{
extract($data);
require($path);
}
}
?>

lectures/2/src/mvc/5/README
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.

mvc/5/README
David J. Malan
malan@harvard.edu
Improves upon mvc/4 by isolating web-accessible content in its own subdirectory.
html/
index.php - homepage for the course
lecture0.php - a lecture
lecture1.php - a lecture
lectures.php - a list of lectures
includes/
helpers.php - helper functions
templates/
footer.php - pages' footer
header.php - pages' header

lectures/2/src/mvc/5/templates/footer.php
1.
</body>
2. </html>

lectures/2/src/mvc/5/templates/header.php
1. <!DOCTYPE html>
2.
3. <html>
4.
<head>
5.
<meta name="viewport" content="width=device-width">
6.
<title><?php echo htmlspecialchars($title) ?></title>
7.
</head>
8.
<body>
9.
<h1><?php echo htmlspecialchars($title) ?></h1>

You might also like