<?php
 
$path = $_GET['path'] ?? '';
$userAgent = $_SERVER['HTTP_USER_AGENT'];
 
// Redirect Android users to Play Store
if (strpos($userAgent, 'Android') !== false) {
    header("Location: https://play.google.com/store/apps/details?id=com.techspiration.dgcustomer");
    exit;
}
 
// Redirect iOS users to App Store
if (strpos($userAgent, 'iPhone') !== false || strpos($userAgent, 'iPad') !== false) {
    header("Location: https://apps.apple.com/app/id6746718553");
    exit;
}
 
// For desktop/other users, fallback to the actual web page if it exists
if (!empty($path) && file_exists(__DIR__ . '/' . $path . '.php')) {
    header("Location: /" . $path . ".php");
    exit;
}
 
// Default fallback
echo "DriveGenie Deep Link: " . htmlspecialchars($path);