Program 8
Program 8
a. Develop a PHP program (with HTML/CSS) to keep track of the number of visitors visiting the web page
and to display this count of visitors, with relevant headings.
How to Run:
Create a file name called index.php, copy the below code and paste it and save it.
Copy index.php file and open XAAMP directory if installed else install it .
There you’ll find a folder named “htdocs”.
Inside the “htdocs” folder, paste index.php file.
After then open your XAAMP and start the Apache server.
Open your Google Chrome .
Then, go to the URL “http://localhost/index.php“.
index.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Visitor Counter</title>
<style>
body {
background-color: #f4f4f4;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
.container {
text-align: center;
background-color: white;
border-radius: 10px;
h1 {
font-size: 2.5rem;
color: #333;
h2 {
font-size: 1.5rem;
color: #666;
p{
font-size: 1.25rem;
color: #444;
}
.count {
font-size: 2rem;
font-weight: bold;
color: #2c3e50;
</style>
</head>
<body>
<div class="container">
<h1>Welcome to My Website!</h1>
<h2>Visitor Counter</h2>
<?php
$counter_file = "counter.txt";
if (!file_exists($counter_file)) {
file_put_contents($counter_file, 0);
$count++;
file_put_contents($counter_file, $count);
?>
</div>
</body>
</html>
Output:
8b. Develop a PHP program (with HTML/CSS) to sort the student records which are stored in the
database using selection sort.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
body {
background-color: #f4f4f4;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.container {
background-color: white;
border-radius: 10px;
width: 80%;
max-width: 800px;
h1 {
text-align: center;
font-size: 2rem;
color: #333;
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
table, th, td {
th, td {
padding: 12px;
text-align: left;
th {
background-color: #f4f4f4;
color: #333;
</style>
</head>
<body>
<div class="container">
<?php
if ($conn->connect_error) {
}
// Query to fetch student records
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$students = [];
$students[] = $row;
$n = count($students);
$minIndex = $i;
$minIndex = $j;
$temp = $students[$i];
$students[$i] = $students[$minIndex];
$students[$minIndex] = $temp;
echo "<table>";
echo "<tr><th>ID</th><th>Name</th><th>Marks</th></tr>";
echo "<tr>
</tr>";
echo "</table>";
} else {
$conn->close();
?>
</div>
</body>
</html>