![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/domains/soundstudiopro.com/public_html/ |
<?php
// AJAX Page Loader - Loads page content without full page refresh
// Preserves global player state across navigation
session_start();
require_once 'config/database.php';
// Set JSON header
header('Content-Type: application/json');
// Prevent caching of AJAX responses
header('Cache-Control: no-cache, no-store, must-revalidate, max-age=0');
header('Pragma: no-cache');
header('Expires: 0');
// Get requested page and parameters
$page = $_GET['page'] ?? '';
$params = $_GET;
unset($params['page']); // Remove page parameter
// Security: Only allow specific pages
// CRITICAL FIX: Removed track.php, artist_profile.php, dashboard.php, community_fixed.php, artist_dashboard.php, and artists.php from AJAX handling - now uses normal navigation
$allowedPages = [
'admin' => 'admin.php' // This one works
// Removed problematic pages: track, artist_profile, dashboard, community_fixed, artist_dashboard, artists, library, studio, events, charts, messages, notifications
];
if (!isset($allowedPages[$page])) {
echo json_encode(['success' => false, 'error' => 'Invalid page']);
exit;
}
$targetFile = $allowedPages[$page];
if (!file_exists($targetFile)) {
echo json_encode(['success' => false, 'error' => 'Page not found']);
exit;
}
try {
// Start output buffering to capture the page content
ob_start();
// Set up $_GET parameters for the target page
foreach ($params as $key => $value) {
$_GET[$key] = $value;
}
// IMPORTANT: Set ajax parameter for pages that check it
$_GET['ajax'] = '1';
// Check if this is an authentication-required page
$authRequiredPages = ['dashboard', 'library', 'profile'];
if (in_array($page, $authRequiredPages)) {
// Ensure session is started and user is logged in
if (!isset($_SESSION['user_id'])) {
echo json_encode([
'success' => false,
'error' => 'Authentication required',
'redirect' => '/auth/login_new.php'
]);
exit;
}
}
// Include the target page
include $targetFile;
// Get the captured content
$content = ob_get_clean();
// Validate content is not empty
if (empty($content)) {
throw new Exception('Page returned empty content');
}
// IMPROVED: Clean up content for AJAX loading - Prevent conflicts
// Remove duplicate AJAX navigation scripts
$content = preg_replace('/<script[^>]*src="[^"]*ajax_navigation\.js"[^>]*><\/script>/s', '', $content);
// Remove duplicate global player instances
$content = preg_replace('/<div[^>]*id="enhancedGlobalPlayer"[^>]*>.*?<\/div>/s', '', $content);
// Remove footer completely (keep header for navigation)
$content = preg_replace('/<footer[^>]*>.*?<\/footer>/s', '', $content);
// Remove problematic inline scripts that cause navigation issues
$content = preg_replace('/<script[^>]*>.*?window\.location\.href.*?<\/script>/s', '', $content);
$content = preg_replace('/<script[^>]*>.*?document\.write.*?<\/script>/s', '', $content);
$content = preg_replace('/<script[^>]*>.*?location\.reload.*?<\/script>/s', '', $content);
// CRITICAL FIX: Better header handling for AJAX requests
if (strpos($content, '<header') !== false || strpos($content, '<nav') !== false) {
// Remove header content to prevent duplication
$content = preg_replace('/<header[^>]*>.*?<\/header>/s', '', $content);
// Remove navigation elements
$content = preg_replace('/<nav[^>]*class="[^"]*navbar[^"]*"[^>]*>.*?<\/nav>/s', '', $content);
// Remove any duplicate HTML structure elements
$content = preg_replace('/<html[^>]*>|<\/html>/s', '', $content);
$content = preg_replace('/<body[^>]*>|<\/body>/s', '', $content);
$content = preg_replace('/<head[^>]*>.*?<\/head>/s', '', $content);
// Remove any remaining navigation-related elements
$content = preg_replace('/<div[^>]*class="[^"]*navbar[^"]*"[^>]*>.*?<\/div>/s', '', $content);
$content = preg_replace('/<div[^>]*id="[^"]*navigation[^"]*"[^>]*>.*?<\/div>/s', '', $content);
error_log('📄 Header-including page detected, cleaned for AJAX loading: ' . $page);
}
// Remove any remaining problematic elements
$content = preg_replace('/<div[^>]*class="[^"]*header[^"]*"[^>]*>.*?<\/div>/s', '', $content);
$content = preg_replace('/<div[^>]*id="[^"]*navigation[^"]*"[^>]*>.*?<\/div>/s', '', $content);
// Return successful response
echo json_encode([
'success' => true,
'content' => $content,
'page' => $page,
'title' => ucfirst($page),
'url' => $targetFile . '?' . http_build_query($params)
]);
} catch (Exception $e) {
error_log('AJAX Load Error: ' . $e->getMessage());
echo json_encode([
'success' => false,
'error' => 'Failed to load page: ' . $e->getMessage()
]);
}
?>