s44
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
<div class="container mt-4">
|
||||
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quibusdam mollitia quidem sint dolores nostrum, similique nulla consequuntur. Animi neque labore praesentium ratione a? Facere, quasi ea reprehenderit eum tempora voluptatum.
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
var_dump($_SESSION);
|
||||
// echo $_SESSION['userName'] . $_SESSION['userEmail'] . $_SESSION['userType'] . $_SESSION['isLogedin'];
|
||||
?>
|
||||
@@ -21,6 +21,15 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/contact-us">Contact</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<?php
|
||||
if (isset($_SESSION['isLogedin']) && $_SESSION['isLogedin'] === true) {
|
||||
echo '<a class="nav-link" href="/logout">Logout</a>';
|
||||
} else {
|
||||
echo '<a class="nav-link" href="/login">Login</a>';
|
||||
}
|
||||
?>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
54
.hta_slug/login.php
Normal file
54
.hta_slug/login.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['email']) && isset($_POST['password'])) {
|
||||
$userPassword = md5($_POST['password']);
|
||||
|
||||
try {
|
||||
$db = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
|
||||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
$stmt = $db->prepare("SELECT * FROM users WHERE email = :email AND password = :password");
|
||||
$stmt->bindParam(':email', $_POST['email'], PDO::PARAM_STR);
|
||||
$stmt->bindParam(':password', $userPassword, PDO::PARAM_STR);
|
||||
$stmt->execute();
|
||||
|
||||
$user = $stmt->fetch(PDO::FETCH_ASSOC); // Fetch a single record
|
||||
|
||||
if ($user) {
|
||||
$_SESSION['userName'] = $user['name'];
|
||||
$_SESSION['userEmail'] = $user['email'];
|
||||
$_SESSION['userType'] = $user['type'];
|
||||
$_SESSION['isLogedin'] = true;
|
||||
$_SESSION['customerId'] = $user['customerId'];
|
||||
var_dump($_SESSION);
|
||||
echo "Login successful! Welcome, " . htmlspecialchars($user['email']);
|
||||
// var_dump($_SESSION);
|
||||
} else {
|
||||
echo "Invalid email or password.";
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
echo "Error: " . $e->getMessage();
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="d-flex justify-content-center align-items-center vh-100 bg-light">
|
||||
<div class="card p-4 shadow-lg" style="max-width: 400px; width: 100%;">
|
||||
<h3 class="text-center mb-4">Login</h3>
|
||||
<form method="post">
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label">Email address</label>
|
||||
<input type="email" class="form-control" id="email" name="email" placeholder="Enter your email" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">Password</label>
|
||||
<input type="password" class="form-control" id="password" name="password" placeholder="Enter your password" required>
|
||||
</div>
|
||||
<div class="mb-3 form-check">
|
||||
<input type="checkbox" class="form-check-input" id="rememberMe">
|
||||
<label class="form-check-label" for="rememberMe">Remember me</label>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary w-100">Login</button>
|
||||
</form>
|
||||
<p class="text-center mt-3"><a href="#">Forgot password?</a></p>
|
||||
</div>
|
||||
</div>
|
||||
13
.hta_slug/logout.php
Normal file
13
.hta_slug/logout.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
session_start(); // Start the session
|
||||
|
||||
// Unset all session variables
|
||||
$_SESSION = [];
|
||||
|
||||
// Destroy the session
|
||||
session_destroy();
|
||||
|
||||
// Redirect to login page
|
||||
header("Location: /");
|
||||
exit;
|
||||
?>
|
||||
Reference in New Issue
Block a user