152 lines
3.6 KiB
PHP
152 lines
3.6 KiB
PHP
<?php
|
|
//**URL & FOLDERS**\\
|
|
define('URL', 'lipa.kvewijk.nl'); //Base url of site
|
|
define('ROOT', '/manage/'); //Root folder of project (if URL -> /)
|
|
define('PHP', '/manage/php/'); //PHP folder
|
|
|
|
//**SYSTEM INFO**\\
|
|
define('MAIL', 'lipa@kvewijk.nl'); //Email to give out as admin email if user requires help outside system
|
|
define('SYSTEM_MAIL', 'LIPA Streaming <no-reply@lipa.kvewijk.nl>'); //Email which the login system should send from
|
|
define('SYSTEM_MAIL_SIGNATURE', 'Sincerely, <br>LIPA Streaming');
|
|
|
|
//**SESSION**\\
|
|
define('SESSION_TIME', '24:00:00'); //Set session time, ignored if rememer me is selected (format: H:i:s)
|
|
|
|
//**DATABASE**\\
|
|
define('DATABASE_NAME', 'kennybo1_lipa'); //Database name
|
|
define('DATABASE_USER', 'kennybo1_lipa'); //Database user
|
|
define('DATABASE_PASS', 'boef1239'); //Database password
|
|
|
|
//-- Global Config Variables --\\
|
|
|
|
function ExceptionHandler($exception) {
|
|
echo "An exception occured: " . $exception->getMessage();
|
|
exit;
|
|
}
|
|
|
|
set_exception_handler('ExceptionHandler');
|
|
|
|
$mysqli = new mysqli("localhost", DATABASE_USER, DATABASE_PASS, DATABASE_NAME);
|
|
|
|
if ($mysqli->connect_errno) {
|
|
echo "Sorry, this website is experiencing problems.";
|
|
echo "Error: Failed to make a MySQL connection, here is why: \n";
|
|
echo "Errno: " . $mysqli->connect_errno . "\n";
|
|
echo "Error: " . $mysqli->connect_error . "\n";
|
|
exit;
|
|
}
|
|
|
|
//Query
|
|
function ExecQuery($mysqli, $sql)
|
|
{
|
|
if (!$result = $mysqli->query($sql)) {
|
|
echo "Error: Query failed: \n";
|
|
echo "Query: " . $sql . "\n";
|
|
echo "Errno: " . $mysqli->errno . "\n";
|
|
echo "Error: " . $mysqli->error . "\n";
|
|
exit;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
|
|
//Session management
|
|
function destroySession()
|
|
{
|
|
setcookie('session', '', 0, substr(ROOT, 0, -1), URL);
|
|
}
|
|
|
|
function setSession($session_id)
|
|
{
|
|
setcookie('session', base64_encode($session_id), time()+60*60*24*365, substr(ROOT, 0, -1), URL);
|
|
}
|
|
|
|
function getSession()
|
|
{
|
|
if(isSession())
|
|
{
|
|
return base64_decode($_COOKIE['session']);
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function isSession()
|
|
{
|
|
return isset($_COOKIE['session']);
|
|
}
|
|
|
|
|
|
//Log out
|
|
function logout($error)
|
|
{
|
|
$link = PHP . "session/logout.php?error=" . $error;
|
|
die(header("Location: $link"));
|
|
}
|
|
|
|
//Create message
|
|
function error($page, $msg)
|
|
{
|
|
$link = ROOT . $page . "?error=" . $msg;
|
|
die(header("Location: $link"));
|
|
}
|
|
|
|
function warning($page, $msg)
|
|
{
|
|
$link = ROOT . $page . "?warning=" . $msg;
|
|
die(header("Location: $link"));
|
|
}
|
|
|
|
function success($page, $msg)
|
|
{
|
|
$link = ROOT . $page . "?success=" . $msg;
|
|
die(header("Location: $link"));
|
|
}
|
|
|
|
function info($page, $msg)
|
|
{
|
|
$link = ROOT . $page . "?info=" . $msg;
|
|
die(header("Location: $link"));
|
|
}
|
|
|
|
function RandomString($length)
|
|
{
|
|
//Generate Session ID
|
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
$str = '';
|
|
for ($i = 0; $i < $length; $i++) {
|
|
$str .= $characters[rand(0, strlen($characters) - 1)];
|
|
}
|
|
|
|
return $str;
|
|
}
|
|
|
|
|
|
function sendMail($to, $subject, $msg)
|
|
{
|
|
$header = "From: " . SYSTEM_MAIL . "\r\n";
|
|
$header .= "Reply-To: " . MAIL . "\r\n";
|
|
$header .= 'MIME-Version: 1.0' . "\r\n";
|
|
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
|
|
$msg .= "\n\n" . SYSTEM_MAIL_SIGNATURE;
|
|
$msg .= "\n-----------------------------------\nThis message is automatically generated.";
|
|
$msg = str_replace("\n", "<br>", $msg);
|
|
|
|
if(mail($to, $subject, $msg, $header))
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
$connected = true;
|
|
$loggedin = false;
|
|
?>
|
|
|