-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.php
More file actions
36 lines (29 loc) · 799 Bytes
/
Copy pathconfig.php
File metadata and controls
36 lines (29 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
session_start();
// Database configuration
define('DB_HOST', 'localhost');
define('DB_NAME', 'copywriting_course');
define('DB_USER', 'root');
define('DB_PASS', '');
try {
$pdo = new PDO("mysql:host=" . DB_HOST . ";dbname=" . DB_NAME, DB_USER, DB_PASS);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
die("Connection failed: " . $e->getMessage());
}
// Helper functions
function isLoggedIn() {
return isset($_SESSION['user_id']);
}
function requireLogin() {
if (!isLoggedIn()) {
header('Location: login.php');
exit();
}
}
function getUserData($pdo, $user_id) {
$stmt = $pdo->prepare("SELECT * FROM users WHERE id = ?");
$stmt->execute([$user_id]);
return $stmt->fetch(PDO::FETCH_ASSOC);
}
?>