104 lines
2.6 KiB
PHP
104 lines
2.6 KiB
PHP
|
<?php
|
||
|
session_start();
|
||
|
|
||
|
// Error reporting
|
||
|
if (getenv('DEBUG_MODE') === 'true') {
|
||
|
ini_set('display_errors', 1);
|
||
|
ini_set('display_startup_errors', 1);
|
||
|
error_reporting(E_ALL);
|
||
|
} else {
|
||
|
ini_set('display_errors', 0);
|
||
|
error_reporting(0);
|
||
|
}
|
||
|
|
||
|
// Load environment variables
|
||
|
$env = parse_ini_file(__DIR__ . '/../.env');
|
||
|
|
||
|
// Database configuration
|
||
|
define('DB_SERVER', 'localhost');
|
||
|
define('DB_USERNAME', 'momaher');
|
||
|
define('DB_PASSWORD', 'Mohamed@9498#');
|
||
|
define('DB_NAME', 'shubraveil_db');
|
||
|
|
||
|
// Site configuration
|
||
|
define('SITE_NAME', 'ShubraVeil');
|
||
|
define('SITE_URL', $env['SITE_URL']);
|
||
|
define('UPLOAD_PATH', __DIR__ . '/../uploads');
|
||
|
define('ALLOWED_IMAGE_TYPES', ['image/jpeg', 'image/png', 'image/webp']);
|
||
|
define('MAX_IMAGE_SIZE', 5 * 1024 * 1024); // 5MB
|
||
|
|
||
|
// Email configuration
|
||
|
define('SMTP_HOST', $env['SMTP_HOST']);
|
||
|
define('SMTP_PORT', $env['SMTP_PORT']);
|
||
|
define('SMTP_USERNAME', $env['SMTP_USERNAME']);
|
||
|
define('SMTP_PASSWORD', $env['SMTP_PASSWORD']);
|
||
|
define('SMTP_FROM_EMAIL', $env['SMTP_FROM_EMAIL']);
|
||
|
define('SMTP_FROM_NAME', $env['SMTP_FROM_NAME']);
|
||
|
|
||
|
// Security configuration
|
||
|
define('JWT_SECRET', $env['JWT_SECRET']);
|
||
|
define('RECAPTCHA_SITE_KEY', $env['RECAPTCHA_SITE_KEY']);
|
||
|
define('RECAPTCHA_SECRET_KEY', $env['RECAPTCHA_SECRET_KEY']);
|
||
|
|
||
|
// Cache configuration
|
||
|
define('CACHE_ENABLED', true);
|
||
|
define('CACHE_PATH', __DIR__ . '/../cache');
|
||
|
define('CACHE_DURATION', 3600); // 1 hour
|
||
|
|
||
|
// Time zone
|
||
|
date_default_timezone_set('Africa/Cairo');
|
||
|
|
||
|
// Functions
|
||
|
function sanitize_input($data) {
|
||
|
global $conn;
|
||
|
return mysqli_real_escape_string($conn, htmlspecialchars(trim($data)));
|
||
|
}
|
||
|
|
||
|
function generate_csrf_token() {
|
||
|
if (!isset($_SESSION['csrf_token'])) {
|
||
|
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
|
||
|
}
|
||
|
return $_SESSION['csrf_token'];
|
||
|
}
|
||
|
|
||
|
function verify_csrf_token($token) {
|
||
|
return isset($_SESSION['csrf_token']) && hash_equals($_SESSION['csrf_token'], $token);
|
||
|
}
|
||
|
|
||
|
function is_logged_in() {
|
||
|
return isset($_SESSION['user_id']);
|
||
|
}
|
||
|
|
||
|
function is_admin() {
|
||
|
return isset($_SESSION['user_role']) && $_SESSION['user_role'] === 'admin';
|
||
|
}
|
||
|
|
||
|
function redirect($path) {
|
||
|
header("Location: " . SITE_URL . $path);
|
||
|
exit();
|
||
|
}
|
||
|
|
||
|
function flash_message($type, $message) {
|
||
|
$_SESSION['flash'] = [
|
||
|
'type' => $type,
|
||
|
'message' => $message
|
||
|
];
|
||
|
}
|
||
|
|
||
|
function get_flash_message() {
|
||
|
if (isset($_SESSION['flash'])) {
|
||
|
$flash = $_SESSION['flash'];
|
||
|
unset($_SESSION['flash']);
|
||
|
return $flash;
|
||
|
}
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
// API Response helper
|
||
|
function json_response($data, $status = 200) {
|
||
|
header('Content-Type: application/json');
|
||
|
http_response_code($status);
|
||
|
echo json_encode($data);
|
||
|
exit();
|
||
|
}
|