Hallo
ich möchte gerne einstellen das die Bilder nur für angemeldete user sichtbar sind.
dazu habe ich ein PHP script gefunden, allerdings scheint dies bei mir nicht so richtig zu funktionieren(es werden keine bilder mehr angezeigt obwohl ich eingeloggt bin als admin user)
.htaccess
isAuthenticated.php
Code
require_once("wp-blog-header.php");
$allowedExtensions = array("jpg", "gif", "png");
$path = $_SERVER["DOCUMENT_ROOT"].DIRECTORY_SEPARATOR.$_REQUEST["path"];
$pathInfo = pathinfo($path);
// Check if the Wordpress user is logged in and if the file extension is allowed
// @see https://codex.wordpress.org/Function_Reference/is_user_logged_in
if (!is_user_logged_in() || !in_array($pathInfo["extension"], $allowedExtensions)) {
header("HTTP/1.1 403 Forbidden");
exit;
}
if(!file_exists($path)) {
header("HTTP/1.1 404 Not Found");
exit;
}
// Display the file and set the correct mimetype
$resource = finfo_open(FILEINFO_MIME_TYPE);
$mimetype = finfo_file($resource, $path);
finfo_close($resource);
header("Content-Type: ".$mimetype);
readfile($path);
Alles anzeigen
gibt es da evtl. eine andere variante?
Danke und Gruss