diff --git a/src/read.php b/src/read.php
index d415ea2..4a98a77 100644
--- a/src/read.php
+++ b/src/read.php
@@ -1,24 +1,46 @@
where("identifier", $_GET['id']);
+// Using prepared statements to avoid SQL injections
+$db->where("identifier", $id);
$qrcode = $db->getOne("dynamic_qrcodes");
-$data = array (
+if (!$qrcode) {
+ die("QR code not found");
+}
+
+$data = array(
'scan' => $db->inc(1)
);
-$db->where("identifier", $_GET['id']);
-$db->update ('dynamic_qrcodes', $data);
-
- if($qrcode['state'] == 'enable'){
- echo '';
+
+$db->where("identifier", $id);
+if (!$db->update('dynamic_qrcodes', $data)) {
+ die("Failed to update scan count");
+}
+
+if ($qrcode['state'] == 'enable') {
+ // Validation and escaping of the URL to avoid XSS attacks
+ $link = filter_var($qrcode['link'], FILTER_VALIDATE_URL);
+ if ($link) {
+ echo '';
echo 'Loading...'; // You can include a custom page to display during the redirect
+ } else {
+ echo 'Invalid URL';
}
- else
- echo 'Disabled link';
+} else {
+ echo 'Disabled link';
+}
?>