b2in/public/_cabinet/go.php
2026-01-23 17:33:10 +01:00

87 lines
3.2 KiB
PHP

<?php
/*
Redirect-Script mit Datenbanklogging für Display-Footer-Inhalte
Funktioniert sowohl in _display-b2in-eu als auch in _cabinet
Aufruf via: https://cabinet.b2in.eu/go.php?z=abc123
*/
// Datenbankverbindung direkt (ohne Laravel Bootstrap)
// Lade .env Datei
$envFile = __DIR__ . '/../../.env';
if (file_exists($envFile)) {
$lines = file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
if (strpos(trim($line), '#') === 0) continue;
if (strpos($line, '=') === false) continue;
list($name, $value) = explode('=', $line, 2);
$name = trim($name);
$value = trim($value);
if (!getenv($name)) {
putenv("$name=$value");
}
}
}
$dbHost = getenv('DB_HOST') ?: 'mysql';
$dbName = getenv('DB_DATABASE') ?: 'b2in';
$dbUser = getenv('DB_USERNAME') ?: 'sail';
$dbPass = getenv('DB_PASSWORD') ?: 'password';
$shortCode = isset($_GET['z']) ? $_GET['z'] : '';
if (empty($shortCode)) {
http_response_code(404);
echo "Kein Ziel angegeben.";
exit;
}
try {
// PDO-Verbindung zur Datenbank
$pdo = new PDO("mysql:host={$dbHost};dbname={$dbName};charset=utf8mb4", $dbUser, $dbPass, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]);
// Suche den Footer-Content mit diesem Short-Code
$stmt = $pdo->prepare("SELECT * FROM display_footer_contents WHERE short_code = ? LIMIT 1");
$stmt->execute([$shortCode]);
$footerContent = $stmt->fetch();
if ($footerContent) {
// Klicks erhöhen
$updateStmt = $pdo->prepare("UPDATE display_footer_contents SET clicks = clicks + 1 WHERE id = ?");
$updateStmt->execute([$footerContent['id']]);
// Optional: Logging in Datei
$logEntry = date('Y-m-d H:i:s') . " - Code: {$shortCode} - Headline: {$footerContent['headline']} - URL: {$footerContent['url']}\n";
@file_put_contents(__DIR__ . '/clicks.log', $logEntry, FILE_APPEND);
// Redirect zur Original-URL
header("Location: " . $footerContent['url']);
exit;
}
// Fallback: Alte Codes für Rückwärtskompatibilität
$alteCodes = [
't' => 'https://www.cabinet.de/bielefeld?utm_source=store_display&utm_medium=qr_code&utm_campaign=bielefeld_pos&utm_content=termin_buchung#c39393',
't1' => 'https://www.cabinet.de/bielefeld?utm_source=store_display&utm_medium=qr_code&utm_campaign=bielefeld_pos&utm_content=termin_buchung#c39393',
'p' => 'https://de.pinterest.com/cabinet_AG/',
'i' => 'https://www.instagram.com/cabinet_schranksysteme/',
'f' => 'https://de-de.facebook.com/cabinetschranksysteme/'
];
if (isset($alteCodes[$shortCode])) {
$logEntry = date('Y-m-d H:i:s') . " - Legacy Code: {$shortCode}\n";
@file_put_contents(__DIR__ . '/clicks.log', $logEntry, FILE_APPEND);
header("Location: " . $alteCodes[$shortCode]);
exit;
}
http_response_code(404);
echo "Ziel nicht gefunden.";
} catch (PDOException $e) {
error_log("Display Go.php Database Error: " . $e->getMessage());
http_response_code(500);
echo "Ein Fehler ist aufgetreten.";
}