2020 Solution
2020 Solution
Here’s a PHP-based webpage that records and displays the total number of visits and the last
visit time of a user using cookies.
This code will count visits and display the last visit timestamp in an attractive interface.
<?php
// Set visit count cookie
$visitCount = isset($_COOKIE['visit_count']) ? $_COOKIE['visit_count'] + 1 :
1;
setcookie("visit_count", $visitCount, time() + (86400 * 365), "/"); // Cookie
lasts 1 year
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Visitor Counter</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
text-align: center;
padding: 50px;
}
.container {
background: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
display: inline-block;
}
h1 {
color: #333;
}
p {
font-size: 18px;
color: #666;
}
.reset-btn {
background: red;
color: white;
border: none;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
border-radius: 5px;
margin-top: 10px;
}
.reset-btn:hover {
background: darkred;
}
</style>
</head>
<body>
<div class="container">
<h1>Website Visitor Counter</h1>
<p><strong>Total Visits:</strong> <?php echo $visitCount; ?></p>
<p><strong>Last Visit:</strong> <?php echo $lastVisit; ?></p>
<form method="post">
<button type="submit" name="reset" class="reset-btn">Reset
Counter</button>
</form>
</div>
<?php
// Reset button logic to clear cookies
if (isset($_POST['reset'])) {
setcookie("visit_count", "", time() - 3600, "/");
setcookie("last_visit", "", time() - 3600, "/");
echo "<script>window.location.href='';</script>";
}
?>
</body>
</html>
Output Preview:
📌 A clean and modern visitor counter with the number of visits, last visit time, and reset
functionality.
Would you like any enhancements, such as storing visitor data in a database instead of cookies?
😊🚀
1. Avoids data duplication – Instead of storing repeated data in one table, we use joins to
link related data.
2. Retrieves data efficiently – Fetches related data in a single query instead of multiple
queries.
3. Maintains data consistency – Ensures data is structured properly across different tables.
🔹 Returns all records from the left table and matching records from the right table.
🔹 Example: Get all users, even if they haven’t placed an order.
🔹 Returns all records from the right table and matching records from the left table.
🔹 Example: Get all orders, even if the user is missing.
👉 Shows all users and all orders, even if they don't match.
Widgets in Flutter
In Flutter, widgets are the fundamental building blocks of the user interface (UI). Everything in
Flutter, including layout, text, buttons, and even the entire screen, is a widget. Widgets define
both the structure and behavior of the UI, making Flutter a declarative framework.
2. Stateful Widgets
o These widgets can change dynamically based on user interaction or data updates.
o They maintain a state, allowing updates without rebuilding the entire UI.
o Example:
o class MyStatefulWidget extends StatefulWidget {
o @override
o _MyStatefulWidgetState createState() =>
_MyStatefulWidgetState();
o }
o
o class _MyStatefulWidgetState extends State<MyStatefulWidget> {
o int counter = 0;
o
o void incrementCounter() {
o setState(() {
o counter++;
o });
o }
o
o @override
o Widget build(BuildContext context) {
o return Column(
o children: [
o Text("Counter: $counter"),
o ElevatedButton(onPressed: incrementCounter, child:
Text("Increment"))
o ],
o );
o }
o }
1. Structural Widgets
2. Interactive Widgets
6. Platform-Specific Widgets
Flutter supports different platforms (mobile, web, desktop) with specific widgets:
Conclusion
Widgets in Flutter are essential for UI design and development across multiple platforms. By
using a combination of stateless, stateful, structural, interactive, and platform-specific
widgets, developers can create responsive and dynamic applications for mobile, web, and
desktop efficiently.
💯 This is all you need to prepare for your exam in the easiest way! Let me know if you need
anything else. 🚀