| |
|
|
| |
|
|
| |
| |
|
|
BA 372 - LAMP Lab
This lab familiarizes you with the Linux/Apache/MySQL/PHP stack. We
will write some PHP programs, and deploy them on a Linux machine
running the Apache web server. One of the PHP programs will conduct
queries to the MySQL database you will work on in Assignment 2.
<?
phpinfo();
?>
http://oregonstate.edu/~your_ONID_login/info.php
<html><body><p>Here's an
example</p><? phpinfo();?></body></html>
<html>
<ol>
<?
for
($i = 1; $i <= 10; $i++)
print ("<li>Hello,
World...</li>");
?>
</ol>
</html>
<html>
<?
for ($i = 1; $i <= 10; $i++)
{
print ($i);
print (": Hello, World...<br/>") ;
}
?>
</html>
<html>
<?
for ($i = 1; $i <= 10; $i++)
print ($i . ": Hello,
World...<br/>") ;
?>
</html>
<html>
<?
$my_array[0] = 1;
$my_array[1] = -99.99;
$my_array[2] = "mystring";
for ($i = 0; $i < 3; $i++)
print ($i+1 . ":" . $my_array[$i] .
"<br/>");
?>
</html>
<html>
<body>
<form method="get" action="http://oregonstate.edu/~your_login/add.php">
First
Number: <input type="text"
size="5" maxlength="5"
name="Fnumber"><br
/>
Last
Number: <input type="text"
size="5" maxlength="5"
name="Lnumber"><br
/>
<input
type="submit" value="add...">
</form>
</body>
</html>
<html>
<body>
<?
$first=$_GET["Fnumber"];
$last=$_GET["Lnumber"];
print($first . "+" . $last . "=" . ($first+$last));
?>
</body>
</html>
<html>
<body>
<?
$first=$_GET["Fnumber"];
$last=$_GET["Lnumber"];
if($first
&& $last)
{
print($first . "+" . $last . "=" . ($first+$last));
exit(0);
}
?>
<form
method="get" action="<? echo $PHP_SELF;?>">
First
Number: <input type="text" size="5" maxlength="5"
name="Fnumber"><br />
Last
Name: <input type="text" size="5" maxlength="5"
name="Lnumber"><br />
<input
type="submit" value="add...">
</form>
</body>
</html>
<html><body>
<?
$CROSS = 1;
$NOUGHTS = -1;
$EMPTY = 0;
//Set cell values (restore state of the board from parameters '1' - '9')
$cells = array(0, 0, 0, 0, 0, 0, 0, 0, 0);
for ($c = 0; $c < 9; $c++)
$cells[$c] = $_GET[$c + 1]; //$_GET is an associative array of URL
parameters.
//Calculate move number
if ($_GET["move_count"])
$move_number = $_GET["move_count"];
else
$move_number = 1;
//Check if move is valid
$the_move = $_GET["user_input"];
if (strlen($the_move) == 1 && is_numeric($the_move) &&
$the_move <= 9 && $the_move >= 1 &&
$cells[$the_move - 1] == 0)
{
$move_valid = "True";
$on_turn = $_GET["turn"];
$cells[$the_move - 1] = $on_turn; // records the move
$on_turn = $on_turn * -1;
$move_number += 1;
}
else
{
$move_valid = "False";
if ($move_number == 1) // first turn
$on_turn = $CROSS;
else
$on_turn = $_GET["turn"];
}
//Render
table
echo "<table border=2 cellpadding=2 cellspacing=2>\n";
for ($row = 0; $row < 3; $row++) //Traverse the rows
{
echo "<tr>";
for ($col = 0; $col < 3; $col++) //Traverse the cols
{
$pos = (3*$row)+$col;//Calculate the position in the array
echo "<td width=20
align='center'>".render_cell($cells[$pos])."</td>";
}
echo "</tr>\n";
}
echo "</table>\n";
?>
<hr
/>
<?
//Invalid turn message (echo after display of the board
if ($move_valid == "False" && count($_GET) > 0)
echo "Invalid move...<br />\n";
?>
$cells = array(0,
0, 0, 0, 0, 0, 0, 0, 0);
for
($c = 0; $c < 9; $c++)
$cells[$c] = $_GET[$c + 1];
<html>
<body>
<form method="get" action="set_cookie.php">
First Name: <input type="text" size="20"
maxlength="20"
name="Fname"><br />
Last Name: <input type="text" size="20"
maxlength="20"
name="Lname"><br />
<input type="submit" value="I want to
register...">
</form>
</body>
</html>
<?
setcookie("FirstName", $_GET["Fname"], time()+3600);
setcookie("LastName", $_GET["Lname"], time()+3600);
?>
<html><body>
Thanks for registering...
<a href="get_cookie.php">See if we can get the cookie
values</a>
</body></html>
<html>
<body>
Welcome back <? print($_COOKIE["FirstName"] . " " .
$_COOKIE["LastName"] ); ?>
</body>
</html>
<html><body>
<?
mysql_connect("host_name",
"database_login", "password") or die("Could
not
connect: " . mysql_error());
$dbconnected = mysql_select_db("database_name");
if(!$dbconnected)
die("Failed to connect to database.");
$result = mysql_query("select month(timestamp), count(*) from
action
group by month(timestamp)");
while($line = mysql_fetch_row($result))
print("<p>" . $line[0] . " " . $line[1] .
"</p>");
mysql_close();
?>
</body></html>