This commit is contained in:
louiscklaw
2025-01-31 19:15:17 +08:00
parent 09adae8c8e
commit 6c60a73f30
1546 changed files with 286918 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Lab06 Task 1</title>
</head>
<?php
$myForm = <<<EOD
<form method="POST" action="Lab06_1.php">
<h1>I can tell who you are if you visit this page again within next 2 minutes</h1>
<p>Your name:<input type=text name=username></p>
<p>Preferred color:<input type=text name=color></p>
<input type=submit value="Write Cookie">
<input type="reset" value="Reset">
</form>
EOD;
if(isset($_COOKIE["color"])){
echo "<body bgcolor=$_COOKIE[color]> Welcome back $_COOKIE[username]";
}else if(isset($_POST["username"])){
setcookie("username",$_POST["username"],time() + 2*60);
setcookie("color",$_POST["color"],time() + 2*60);
echo "<body> I have created a cookie to remember your submitted information You are $_POST[username] and preferred background color is $_POST[color] Reload this page or visit agin, you will see my welcome message";
}else{
echo $myForm;
}
?>
</body>
</html>

View File

@@ -0,0 +1,30 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Lab06 Task2</title>
</head>
<body>
<?php
$myForm = <<<EOD
<form method="post" action="$_SERVER[PHP_SELF]">
<h1>Session Demo Page</h1>
<p>Programming language: <input type=text name=tfLang> will be stored in a session variable</p>
<button type=submit>Submit</button>
<button type=reset>Reset</button>
</form>
EOD;
if (isset($_POST['tfLang'])) {
session_start();
$_SESSION['lang'] = $_POST['tfLang'];
echo "\$_POST['tfLang'] = $_POST[tfLang] <br> \$_SESSION['lang'] = $_SESSION[lang]";
} else {
echo $myForm;
}
?>
</body>
</html>

View File

@@ -0,0 +1,26 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Lab06 Task 3</title>
</head>
<?php
session_start();
if(isset($_POST["golQty"])){
$_SESSION['Golf Pants'] = $_POST["golQty"];
}
if(isset($_POST["wovQty"])){
$_SESSION['Woven Pants'] = $_POST["wovQty"];
}
echo "<h2>Your shopping cart contains:</h2><p>";
foreach($_SESSION as $key=>$value){
if($value>0)
echo "$key Qty: $value<br>";
}
echo "</p>";
session_destroy();
?>
<body>
</body>
</html>

View File

@@ -0,0 +1,42 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Lab06 Task 3</title>
</head>
<body>
<?php
session_start();
if(isset($_POST["runQty"])){
$_SESSION["Running Shoe"] = $_POST["runQty"];
}
if(isset($_POST["tenQty"])){
$_SESSION["Tennis Shoe"] = $_POST["tenQty"];
}
$myForm = <<<EOD
<form method="POST" action="OrderList.php">
<h1>Sport Pants</h1>
<table border=1>
<tr>
<th>Model Name</th>
<th>Quantity</th>
</tr>
<tr>
<td>Golf Pants</td>
<td><input type=number name=golQty></td>
</tr>
<tr>
<td>Woven Pants</td>
<td><input type=number name=wovQty></td>
</tr>
</table><br>
<button type=submit>Submit</button>
</form>
EOD;
echo $myForm;
?>
</body>
</html>