contentdispenser/index.php
2023-06-12 15:46:23 +02:00

56 lines
2.1 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()) {
if (empty($_POST['action'])){
$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 = "Page view";
$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();
$content = str_replace("__LINK_ID__",$idcko,$content);
echo $content;
}
}
else{
$action = $_POST['action'];
$extrainfo = $_POST['extrainfo'];
$stmt4 = $mysqli->prepare("INSERT INTO Logs (`Action`, `ExtraInfo`, `LinkID`, `ContentID`, `Datetime`, `Nickname`, `IP`) VALUES (?, ?, ?, ?, ?, ?, ?);");
$stmt4->bind_param('sssssss', $action, $extrainfo, $idcko, $contentid, $curdate, $nickname, $ipcka);
$stmt4->execute();
$stmt4->store_result();
}
}
}
else{
die("No link");
}
?>