
<?php

$valid = 0;
$short_url = filter_input(INPUT_GET, "redirect");
if ($short_url == "") {
    
} else {

    $db_host = 'localhost';
    $db_name = 'akhbar_royal';
    $db_user = 'akhbar_royal';
    $db_password = 'gt4host.com';

    $conn = new mysqli($db_host, $db_user, $db_password, $db_name);
    $query = "SELECT * FROM visits_redirect WHERE short_url = '" . $short_url . "' ";
    $result = $conn->query($query);
    if ($result->num_rows > 0) {
        $valid = 1;
        $row = $result->fetch_assoc();
        $fullUrl = $row['fixed_link'] . '' . $row['origin_url'];
        // print_r($fullUrl);
        echo "<script>location='$fullUrl'</script>";
        /// echo "<script>location='https://google.com'</script>";
        //   header('Location:' . $fullUrl);
        exit;
    } else {
        $valid = 2;
        //  print_r(' Invalid Link! ');
    }
    $conn->close();
}

if ($valid != 1) {
    echo '<html lang="en" dir="rtl" class="">
    <head>
        <meta charset="utf-8">
        <title>Royal Med</title>
    </head>

    <body style="text-align: center;" >
        <div>';



    if ($valid == 2) {
        echo '<h4 style="color: red;font-size: 24px;direction: ltr;">Invalid Link !  </h4>';
    }

    echo '</div></body></html>';
}
?>
