update to mysql

This commit is contained in:
2023-06-10 09:10:10 +02:00
parent 40be40db92
commit 92cdabb7ae
2 changed files with 88 additions and 113 deletions

View File

@@ -4,53 +4,39 @@ $idcko = $_GET['id'];
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");
if(!file_exists("data/logs.json")){
file_put_contents("data/logs.json", "{}");
$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");
}
if(!file_exists("data/pageindex.json")){
file_put_contents("data/pageindex.json", "{}");
}
if(!file_exists("data/contents.json")){
file_put_contents("data/contents.json", "{}");
}
$stranky = json_decode(file_get_contents("data/pageindex.json"), true);
$contents = json_decode(file_get_contents("data/contents.json"), true);
$logs = json_decode(file_get_contents("data/logs.json"), true);
$alllog = "data/all.log";
if(array_key_exists($idcko, $stranky)){
$entry = $stranky[$idcko];
if (!array_key_exists($entry["contentid"], $contents)){
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");
}
$content = $contents[$entry["contentid"]];
$nickname = $entry["nickname"];
$logmessage = "Success from $nickname($idcko), IP: $ipcka\n";
if (!array_key_exists($idcko, $logs)){
$logs[$idcko] = [];
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;
}
$logs[$idcko][] = array("action"=>"Success", "datetime"=>date("H:i:s d.m.Y"), "link"=>$idcko, "nickname"=>$nickname, "ip"=>$ipcka);
file_put_contents("data/logs.json", json_encode($logs, JSON_PRETTY_PRINT));
file_put_contents($alllog, $logmessage, FILE_APPEND);
echo $content;
}
else{
die("Nonexistent link");
}
}
else{
die("No link");