File "cn.php"
Full path: /home/atrmarke/public_html/atrdemolive.site/if/db/cn.php
File
size: 0 KB (2.08 KB bytes)
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_Irfan_Traders";
$password = "Irfan_Traders";
$database = "atrmarke_Irfan_Traders";
// 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;
}
try {
$pdo = new PDO('mysql:host=localhost;dbname=atrmarke_burhan_t', 'atrmarke_burhan_t', 'burhan_t123');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo 'Database connection failed: ' . $e->getMessage();
}
?>