<?php
require_once 'connection.php';
session_start();

if (isset($_GET['token'])) {
    $token = $_GET['token'];
    $verify_query = "SELECT verify_token, status FROM tb_akun WHERE verify_token = '$token' LIMIT 1";
    $verify_sql = mysqli_query($conn, $verify_query);
    $result = mysqli_fetch_assoc($verify_sql);

    if ($result) {
        if ($result['status'] == 0) {
            $clicked_token = $result['verify_token'];
            $update_query = "UPDATE tb_akun SET status = 1 WHERE verify_token = '$token'";
            $update_sql = mysqli_query($conn, $update_query);
            if ($update_sql) {
                $_SESSION['status'] = "success, Akun berhasil diverifikasi. Silahkan login.";
                header('Location: index.php');
                exit;
            } else {
                $_SESSION['status'] = "danger, Terjadi kesalahan saat memverifikasi akun.";
                header('Location: index.php');
                exit;
            }
        } else {
            $_SESSION['status'] = "info, Akun sudah diverifikasi sebelumnya.";
            header('Location: index.php');
            exit;
        }
    } else {
        $_SESSION['status'] = "danger, Token verifikasi tidak valid.";
        header('Location: index.php');
        exit;
    }

}


?>