contentdispenser/index.php

45 lines
1.4 KiB
PHP
Raw Normal View History

2023-06-09 16:00:29 +02:00
<?php
2023-06-10 09:17:05 +02:00
$idcko = $_SERVER['QUERY_STRING'];
2023-06-09 16:00:29 +02:00
if (!empty($idcko)){
2023-06-10 09:10:10 +02:00
$config = json_decode(file_get_contents("data/config.json"), true);
$mysqli = new mysqli($config["mysqlhost"], $config["mysqluser"], $config["mysqlpass"], $config["mysqldb"]);
2023-06-09 16:00:29 +02:00
$ipcka = $_SERVER['REMOTE_ADDR'];
2023-06-10 09:10:10 +02:00
$curdate = date("H:i:s d.m.Y");
2023-06-10 09:17:05 +02:00
2023-06-10 09:10:10 +02:00
$stmt1 = $mysqli->prepare("SELECT `LinkID`, `ContentID`, `Nickname` FROM `Links` WHERE `LinkID` = ?");
$stmt1->bind_param("s", $idcko);
$stmt1->bind_result($linkid, $contentid, $nickname);
$stmt1->execute();
$stmt1->store_result();
if ($stmt1->num_rows() < 1) {
die("Nonexistent link");
2023-06-09 22:06:13 +02:00
}
2023-06-10 09:10:10 +02:00
while ($stmt1->fetch()) {
$stmt2 = $mysqli->prepare("SELECT `Content` FROM Content WHERE `ContentID` = ?");
$stmt2->bind_param("s", $contentid);
$stmt2->bind_result ($content);
$stmt2->execute();
$stmt2->store_result();
if ($stmt2->num_rows() < 1) {
2023-06-09 21:57:35 +02:00
die("Faulty link");
}
2023-06-10 09:10:10 +02:00
while ($stmt2->fetch()) {
$action = "Success";
$stmt3 = $mysqli->prepare("INSERT INTO Logs (`Action`, `LinkID`, `ContentID`, `Datetime`, `Nickname`, `IP`) VALUES (?, ?, ?, ?, ?, ?);");
$stmt3->bind_param('ssssss', $action, $idcko, $contentid, $curdate, $nickname, $ipcka);
$stmt3->execute();
$stmt3->store_result();
echo $content;
2023-06-09 21:45:45 +02:00
}
2023-06-09 16:00:29 +02:00
}
}
else{
2023-06-09 21:57:35 +02:00
die("No link");
2023-06-09 16:00:29 +02:00
}
?>