deepsiteseek / index.php
Taper5749's picture
Custom E-Commerce Showcase Prompt
3b11c5d verified
```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>
```