Skip to content

Commit e78356f

Browse files
authored
added files
1 parent 4a07e10 commit e78356f

File tree

6 files changed

+401
-0
lines changed

6 files changed

+401
-0
lines changed

about.php

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php include 'header.php'; ?>
2+
3+
<main>
4+
<h2>Welcome to My About</h2>
5+
<p>This is the main content area where you can add information about your website.</p>
6+
</main>
7+
8+
<?php include 'footer.php'; ?>

footer.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<footer>
2+
<p>&copy; 2024 My Website. All rights reserved.</p>
3+
<nav>
4+
<a href="#" >Facebook</a>
5+
<a href="#" >Twitter</a>
6+
<a href="#">Instagram</a>
7+
</nav>
8+
</footer>
9+
10+
</body>
11+
</html>

header.php

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<link rel="stylesheet" href="css/form.css">
7+
<title>Simple Header Example</title>
8+
<style>
9+
body {
10+
font-family: Arial, sans-serif;
11+
margin: 0;
12+
padding: 0;
13+
}
14+
header {
15+
background-color: #4CAF50;
16+
color: white;
17+
padding: 10px 0;
18+
text-align: center;
19+
}
20+
nav {
21+
display: flex;
22+
justify-content: center;
23+
gap: 20px;
24+
}
25+
nav a {
26+
color: white;
27+
text-decoration: none;
28+
padding: 8px 16px;
29+
}
30+
nav a:hover {
31+
background-color: #45a049;
32+
}
33+
main {
34+
flex: 1;
35+
padding: 20px;
36+
text-align: center;
37+
}
38+
footer {
39+
background-color: #333;
40+
color: white;
41+
padding: 10px 0;
42+
text-align: center;
43+
}
44+
footer a {
45+
color: #4CAF50;
46+
text-decoration: none;
47+
padding: 0 10px;
48+
}
49+
footer a:hover {
50+
color: #45a049;
51+
}
52+
</style>
53+
</head>
54+
<body>
55+
56+
<header>
57+
<?php
58+
$current_page = basename($_SERVER['PHP_SELF']);
59+
60+
if ($current_page == "about.php") {
61+
echo "<h1>My About</h1>";
62+
} elseif ($current_page == "index.php") {
63+
echo "<h1>My Index</h1>";
64+
}
65+
?>
66+
67+
68+
<nav>
69+
<a href="index.php">Home</a>
70+
<a href="about.php">About</a>
71+
<a href="index.php?page=register">Register</a>
72+
<a href="index.php?page=login">Login</a>
73+
</nav>
74+
</header>
75+
76+
</body>
77+
</html>

index.php

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php include 'header.php'; ?>
2+
3+
<main>
4+
<h2>Welcome to My Website</h2>
5+
<p>This is my first form in php and i am about to validate this</p>
6+
7+
<div class="index_body">
8+
<div class="card" style="margin-top: 10px;margin-bottom: 10px;">
9+
<?php
10+
if (isset($_GET['page'])) {
11+
$page = $_GET['page'];
12+
if ($page == 'login') {
13+
include 'login.php';
14+
} elseif ($page == 'register') {
15+
include 'register.php';
16+
} else {
17+
echo "Invalid page.";
18+
}
19+
}
20+
else
21+
{
22+
echo "Welcome to the homepage!";
23+
}
24+
?>
25+
26+
</div>
27+
</div>
28+
</main>
29+
30+
<?php include 'footer.php'; ?>

login.php

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
include "Database\db_config.php";
3+
?>
4+
<div class="card-header">
5+
<h2>Login</h2>
6+
</div>
7+
<div class="card-body">
8+
<form action="login.php" method="post">
9+
10+
<label>Email</label><br>
11+
<input type="text" id="email" name="email"><br>
12+
<label>Password</label><br>
13+
<input type="text" id="password" name="password"><br>
14+
<button type="submit">Register</button>
15+
</form>
16+
</div>
17+
18+
19+
<?php
20+
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
21+
// Trim and sanitize input
22+
$email = trim($_POST['email']);
23+
$password = trim($_POST['password']);
24+
if (empty($email) || empty($password)) {
25+
echo "Email and password are required.";
26+
exit;
27+
}
28+
$stmt = $conn->prepare("SELECT * FROM users WHERE email = ?");
29+
$stmt->bind_param("s", $email);
30+
$stmt->execute();
31+
$result = $stmt->get_result();
32+
33+
if ($result->num_rows == 1) {
34+
$row = $result->fetch_assoc();
35+
if (password_verify($password, $row['password'])) {
36+
echo "Welcome, " . htmlspecialchars($row['username']) . "!";
37+
session_start();
38+
$_SESSION['user_id'] = $row['id'];
39+
$_SESSION['email'] = $row['email'];
40+
header("Location: index.php");
41+
exit;
42+
} else {
43+
echo "Invalid email or password.";
44+
}
45+
} else {
46+
echo "Invalid email or password.";
47+
}
48+
$stmt->close();
49+
$conn->close();
50+
}
51+
?>

0 commit comments

Comments
 (0)