===================================================================================
============================
<form action="process_login.php" method="POST">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required><br><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required><br><br>
<input type="submit" value="Login">
</form>
===================== process_login.php ===============================
<?php
// Capture form input
$username = $_POST['username'];
$password = $_POST['password'];
// Hardcoded correct credentials (for simplicity)
$correct_username = 'admin';
$correct_password = '12345';
// Check if the credentials are correct
if (isset($username, $password) && $username === $correct_username && $password ===
$correct_password) {
session_start();
// Store the username in the session
$_SESSION['username'] = $username;
// Redirect to dashboard.php
header("Location: dashboard.php");
exit();
} else {
echo "Invalid username or password.";
}
?>
===================== dashboard.php ===============================
<?php
session_start();
// Check if the user is logged in
if (isset($_SESSION['username'])) {
$username = $_SESSION['username'];
echo "Welcome, $username!";
} else {
echo "You are not logged in!";
exit();
}
?>
<!-- Logout link -->
<br><br>
<a href="logout.php">Logout</a>
===================== logout.php ===============================
<?php
session_start(); // Start the session
// Destroy the session
session_unset(); // Clear all session variables
session_destroy(); // Destroy the session
// Redirect to the login page
header("Location: process_login.php");
exit();
?>
===================================================================================
===================================
<form action="process_registration.php" method="POST">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br><br>
<input type="submit" value="Register">
</form>
=============== process_registration.php =================================
<?php
// Capture user data from the form
$username = $_POST['name'];
$email = $_POST['email'];
// Set cookies for name and email (expire in 7 days)
setcookie("name", $username, time() + (86400 * 7), "/"); // 86400 seconds = 1 day
setcookie("email", $email, time() + (86400 * 7), "/");
// Redirect to welcome.php
header("Location: welcome.php");
exit();
?>
=============== welcome.php =================================
<?php
// Check if the cookies are set
if (isset($_COOKIE['name']) && isset($_COOKIE['email'])) {
$username = $_COOKIE['name'];
$email = $_COOKIE['email'];
echo "Welcome, $username!<br>";
echo "Your email is: $email";
} else {
echo "No registration data found.";
}
?>
<!-- Link to clear the registration cookies -->
<br><br>
<a href="clear_registration.php">Clear Registration</a>
=============== clear_registration.php =================================
<?php
// Clear the cookies by setting their expiration time in the past
setcookie("name", "", time() - 3600, "/");
setcookie("email", "", time() - 3600, "/");
// Redirect back to welcome.php
header("Location: welcome.php");
exit();
?>
===================================================================================
=========================
<form action="process_cookie.php" method="POST">
<label for="language">Choose your preferred language:</label>
<select id="language" name="language" required>
<option value="English">English</option>
<option value="French">French</option>
<option value="Spanish">Spanish</option>
</select><br><br>
<input type="submit" value="Submit">
</form>
============ process_cookie.php ================
<?php
// Capture the language from the POST request
$language = $_POST['language'];
// Set a cookie that expires in 30 days
setcookie("language", $language, time() + (86400 * 30), "/"); // 86400 seconds = 1
day
// Redirect to the display_cookie.php page
header("Location: display_cookie.php");
exit();
?>
============ display_cookie.php ================
<?php
// Check if the language cookie is set
if (isset($_COOKIE['language'])) {
$language = $_COOKIE['language'];
echo "Your preferred language is: $language";
} else {
echo "No preferred language set.";
}
?>
<!-- Option to clear the cookie -->
<br><br>
<a href="clear_cookie.php">Clear Language Preference</a>
============ clear_cookie.php ================
<?php
// Delete the language cookie by setting its expiration time in the past
setcookie("language", "", time() - 3600, "/"); // Cookie expired 1 hour ago
// Redirect back to display_cookie.php
header("Location: display_cookie.php");
exit();
?>
===================================================================================
============================
<form action="process_session.php" method="POST">
<label for="color">Favorite Color:</label>
<input type="text" id="color" name="color" required><br><br>
<input type="submit" value="Submit">
</form>
========================== process_session.php
===========================================
<?php
// Start the session
session_start();
// Store the favorite color in the session
$color = $_POST['color'];
$_SESSION['color'] = $color;
// Redirect to display_color.php
header("Location: display_color.php");
exit();
?>
=========display_color.php =============
<?php
// Start the session
session_start();
// Check if the session variable is set
if (isset($_SESSION['color'])) {
// Display the stored favorite color
$color = $_SESSION['color'];
echo "Your favorite color is: $color";
} else {
echo "No favorite color set.";
}
?>
<!-- Add a link to clear the session -->
<br><br>
<a href="clear_session.php">Clear Color</a>
=========clear_session.php =============
<?php
// Start the session
session_start();
// Unset all session variables
session_unset();
// Destroy the session
session_destroy();
// Redirect back to display_color.php
header("Location: display_color.php");
exit();
?>
===================================================================================
==========================
<form action="process_redirect.php" method="POST">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required><br><br>
<input type="submit" value="Submit">
</form>
===========process_redirecr.php =====================
$name = $_POST['name'];
header("Location: thank_you.php?name=" . urlencode($name));
========== thank_you.php ============================
$name = $_GET['name'];
echo "Thank you $name !" ;
===================================================================================
=====================
<form action="process_post.php" method="POST">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required><br><br>
<input type="submit" value="Login">
</form>
=========== processs_post.php ===========
<?php
$email = $_POST['email'];
echo "Your email is: $email";
?>
===================================================================================
=============================
<form action="process.php" method="GET">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required><br><br>
<label for="age">Age:</label>
<input type="number" id="age" name="age" required><br><br>
<input type="submit" value="Submit">
</form>
===== process.php =========
<?php
// Get the values from the GET request
$name = $_GET['name'];
$age = $_GET['age']; // Ensure the key matches the input field's name
// Display the result
echo "Your name is: $name<br>";
echo "Your age is: $age";
?>