File size: 2,736 Bytes
3b11c5d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
```php
<?php
require_once 'database_connection.php';
session_start();

// Visitor tracking
if (!isset($_SESSION['visitor_id'])) {
    $_SESSION['visitor_id'] = session_id();
    
    // Update total visitor count
    $stmt = $pdo->prepare("UPDATE visitor_counts SET total_visits = total_visits + 1");
    $stmt->execute();
}

// Update or insert live visitor
$stmt = $pdo->prepare("INSERT INTO live_visitors (session_id) VALUES (:session_id) 
                      ON DUPLICATE KEY UPDATE last_activity = CURRENT_TIMESTAMP");
$stmt->execute([':session_id' => $_SESSION['visitor_id']]);

// Clean up old live visitors (older than 5 minutes)
$stmt = $pdo->prepare("DELETE FROM live_visitors WHERE last_activity < DATE_SUB(NOW(), INTERVAL 5 MINUTE)");
$stmt->execute();

// Get visitor stats
$totalVisits = $pdo->query("SELECT total_visits FROM visitor_counts")->fetchColumn();
$liveVisitors = $pdo->query("SELECT COUNT(*) FROM live_visitors")->fetchColumn();

// Get all products
$products = $pdo->query("SELECT * FROM products ORDER BY created_at DESC")->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Product Showcase</title>
    <style>
        body { font-family: Arial, sans-serif; max-width: 1200px; margin: 0 auto; padding: 20px; }
        .stats { background: #f5f5f5; padding: 10px; margin-bottom: 20px; border-radius: 5px; }
        .products { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 20px; }
        .product { border: 1px solid #ddd; padding: 15px; border-radius: 5px; }
        .product img { max-width: 100%; height: auto; }
        .product a { display: inline-block; margin-top: 10px; background: #007bff; color: white; padding: 8px 15px; text-decoration: none; border-radius: 4px; }
        .admin-link { float: right; }
    </style>
</head>
<body>
    <div class="stats">
        <span>Total Visitors: <?= $totalVisits ?></span> | 
        <span>Live Visitors: <?= $liveVisitors ?></span>
        <a href="admin_login.php" class="admin-link">Admin Login</a>
    </div>

    <h1>Our Products</h1>
    
    <div class="products">
        <?php foreach ($products as $product): ?>
        <div class="product">
            <img src="<?= htmlspecialchars($product['image_path']) ?>" alt="<?= htmlspecialchars($product['name']) ?>">
            <h3><?= htmlspecialchars($product['name']) ?></h3>
            <p><?= htmlspecialchars($product['description']) ?></p>
            <a href="<?= htmlspecialchars($product['affiliate_url']) ?>" target="_blank">View on Amazon</a>
        </div>
        <?php endforeach; ?>
    </div>
</body>
</html>
```