File "cn.php"
Full path: /home/atrmarke/public_html/atrdemolive.site/inst/db/cn.php
File
size: 1.8 KB B
MIME-type: text/x-php
Charset: utf-8
Download Open Edit Advanced Editor Back
<?php
date_default_timezone_set('Asia/Karachi');
// Database connection parameters
$hostname = "localhost";
$username = "atrmarke_new_install";
$password = "new_install";
$database = "atrmarke_new_install";
// Create a new MySQLi connection
$connection = mysqli_connect($hostname, $username, $password, $database);
// Check connection
if (!$connection) {
die("Connection failed: " . mysqli_connect_error());
}
// Set MySQL timezone
if (!mysqli_query($connection, "SET time_zone = '+05:00'")) {
die("Error setting MySQL timezone: " . mysqli_error($connection));
}
// Select the database
if (!mysqli_select_db($connection, $database)) {
die("Database selection failed: " . mysqli_error($connection));
}
// Calculate the time remaining until midnight
$current_time = time();
$midnight = strtotime('tomorrow midnight');
$seconds_until_midnight = $midnight - $current_time;
// Set session cookie lifetime to expire at midnight
ini_set('session.cookie_lifetime', $seconds_until_midnight);
ini_set('session.gc_maxlifetime', $seconds_until_midnight);
// Start the session
session_start();
// Check if the session has crossed midnight
if (isset($_SESSION['session_start_time'])) {
$session_start_time = $_SESSION['session_start_time'];
$midnight_today = strtotime('today midnight');
if ($session_start_time < $midnight_today) {
// Session started before midnight and now it's past midnight
session_unset(); // Unset all session variables
session_destroy(); // Destroy the session
// Redirect to login page or any other page
header("Location:log/logout.php");
exit();
}
} else {
// Store the session start time
$_SESSION['session_start_time'] = $current_time;
}
?>