0% found this document useful (0 votes)
6 views7 pages

Online Attendance System

The document outlines an Online Attendance System consisting of two main PHP files: index.php for submitting attendance and attendance.php for displaying the recorded attendance. The system validates user input, stores attendance data in a session, and appends it to a text file. It also provides feedback to the user by displaying their attendance status and previous records after submission.

Uploaded by

Suraj Uddansinha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views7 pages

Online Attendance System

The document outlines an Online Attendance System consisting of two main PHP files: index.php for submitting attendance and attendance.php for displaying the recorded attendance. The system validates user input, stores attendance data in a session, and appends it to a text file. It also provides feedback to the user by displaying their attendance status and previous records after submission.

Uploaded by

Suraj Uddansinha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Online Attendance System

Code

index.php (Attendance Form)

<?php
// Initialize the session
session_start();

// Set up error handling and empty input variables


$nameErr = "";
$name = "";

// Process form submission


if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Validate name
if (empty($_POST["name"])) {
$nameErr = "Name is required";
} else {
$name = test_input($_POST["name"]);
}

// If no errors, redirect to attendance.php page with name and current date


if (empty($nameErr)) {
$_SESSION['attendance_data'] = array(
'name' => $name,
'date' => date('Y-m-d'),
'status' => $_POST['status']
);
header("Location: attendance.php");
exit();
}
}

// Sanitize input data


function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Online Attendance System</title>
</head>
<body>
<h2>Mark Your Attendance</h2>

<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">


Name: <input type="text" name="name" value="<?php echo $name;?>">
<span style="color:red;"><?php echo $nameErr;?></span><br><br>

Attendance Status:
<input type="radio" name="status" value="Present" required> Present
<input type="radio" name="status" value="Absent" required> Absent<br><br>

<input type="submit" value="Submit">


</form>

</body>
</html>

attendance.php (Display Attendance)

<?php
// Start the session
session_start();

// Check if attendance data exists


if (!isset($_SESSION['attendance_data'])) {
header("Location: index.php"); // Redirect to index if no attendance data
exit();
}
// Retrieve attendance data
$attendance = $_SESSION['attendance_data'];

// Store the current attendance record to a file


$attendance_file = "attendance_records.txt";
file_put_contents($attendance_file, $attendance['name'] . " - " . $attendance['date'] . " - " .
$attendance['status'] . "\n", FILE_APPEND);

// Reset session to clear the attendance data


session_unset();

// Display the attendance record


?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Attendance Confirmation</title>
</head>
<body>

<h2>Attendance Marked</h2>
<p>Your attendance has been recorded as:</p>
<p><strong>Name:</strong> <?php echo $attendance['name']; ?></p>
<p><strong>Date:</strong> <?php echo $attendance['date']; ?></p>
<p><strong>Status:</strong> <?php echo $attendance['status']; ?></p>

<h3>Previous Attendance Records:</h3>


<pre>
<?php
// Display the attendance records from the file
if (file_exists($attendance_file)) {
echo file_get_contents($attendance_file);
}
?>
</pre>

</body>
</html>
Output

Before (attendance.php):
After (attendance_records.txt):

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy