quiz-klapek/php/functions.php
2025-06-15 22:04:08 +02:00

32 lines
No EOL
752 B
PHP

<?php
const sqlHostname = "localhost";
const sqlUsername = "root";
const sqlPassword = "";
const sqlDatabase = "quizPHP";
function connectDB() {
$conn = new mysqli(sqlHostname, sqlUsername, sqlPassword, sqlDatabase);
if ($conn->connect_error)
exit("Błąd połączenia: " . $conn->connect_error);
return $conn;
}
function jsonMsg($messsage) {
echo json_encode(["msg" => $messsage]);
exit();
}
function checkLogin() {
session_start();
if (isset($_SESSION["UID"]))
return true;
return false;
}
function checkLogged() {
if (isset($_SESSION["username"]))
return true;
return false;
}
function redirectLogged() {
if (!checkLogged()) {
header("Location: /");
exit();
}
}