contentdispenser/index.php
2023-06-10 09:17:05 +02:00

45 lines
1.4 KiB
PHP

<?php
$idcko = $_SERVER['QUERY_STRING'];
if (!empty($idcko)){
$config = json_decode(file_get_contents("data/config.json"), true);
$mysqli = new mysqli($config["mysqlhost"], $config["mysqluser"], $config["mysqlpass"], $config["mysqldb"]);
$ipcka = $_SERVER['REMOTE_ADDR'];
$curdate = date("H:i:s d.m.Y");
$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");
}
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) {
die("Faulty link");
}
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;
}
}
}
else{
die("No link");
}
?>