<?php
// /public_html/bio_click.php
require 'config/db_connect.php';

if (isset($_GET['id'])) {
    $link_id = intval($_GET['id']);
    
    // 1. Get the actual URL
    $stmt = $conn->prepare("SELECT url FROM bio_links WHERE id = ?");
    $stmt->bind_param("i", $link_id);
    $stmt->execute();
    $res = $stmt->get_result();
    
    if ($res->num_rows > 0) {
        $link = $res->fetch_assoc();
        
        // 2. Increment Click Counter
        $conn->query("UPDATE bio_links SET clicks = clicks + 1 WHERE id = $link_id");
        
        // 3. Redirect User
        header("Location: " . $link['url']);
        exit();
    }
}

// Fallback if link invalid
header("Location: index.php");
exit();
?>