現在の言語: 日本語 |
キー判定 |
ajax |
[.htaccess]
RewriteEngine On
# 自分のサイトからの参照のみ許可
# ex.)
# RewriteCond %{HTTP_REFERER} ^https://test\.co\.jp [NC]
RewriteCond %{HTTP_REFERER} ^http://localhost [NC]
RewriteRule ^.*\.(jpe?g|png|gif|bmp)$ - [L]
# それ以外(空リファラ含む)は拒否
RewriteRule ^.*\.(jpe?g|png|gif|bmp)$ - [F,L]
[getkey.php]
header("Access-Control-Allow-Origin: http://localhost");//ex.)https://test.co.jp
header("Access-Control-Allow-Credentials: true");
// 固定キーを返すだけ
header("Content-Type: application/json; charset=utf-8");
echo json_encode(["key" => "password"]);
[image.php]
// --- CORS 設定 ---
header("Access-Control-Allow-Origin: http://localhost");//ex.)https://test.co.jp
header("Access-Control-Allow-Credentials: true");
// --- アクセス元チェック ---
$origin = $_SERVER['HTTP_ORIGIN'] ?? '';
$referer = $_SERVER['HTTP_REFERER'] ?? '';
// --- ここから先は既存のキー判定や画像返却処理 ---
$valid_key = "password"; // 固定キーやトークン判定
$key = $_GET['key'] ?? '';
$file = basename($_GET['file'] ?? '');
if ($key !== $valid_key) {
header("HTTP/1.1 403 Forbidden");
exit("Forbidden");
}
$path = __DIR__ . "/" . $file;
if (!file_exists($path)) {
header("HTTP/1.1 404 Not Found");
exit("Not Found");
}
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $path);
finfo_close($finfo);
header("Content-Type: $mime");
readfile($path);
exit;
copy
[.htaccess]
RewriteEngine On
# Allow access only from your own site
# ex.)
# RewriteCond %{HTTP_REFERER} ^https://test\.co\.jp [NC]
RewriteCond %{HTTP_REFERER} ^http://localhost [NC]
RewriteRule ^.*\.(jpe?g|png|gif|bmp)$ - [L]
# Deny all others (including empty referrers)
RewriteRule ^.*\.(jpe?g|png|gif|bmp)$ - [F,L]
[getkey.php]
header(“Access-Control-Allow-Origin: http://localhost”);//ex.)https://test.co.jp
header(“Access-Control-Allow-Credentials: true”);
// Just return the fixed key
header(“Content-Type: application/json; charset=utf-8”);
echo json_encode([“key” => “password”]);
[image.php]
// --- CORS Configuration ---
header(“Access-Control-Allow-Origin: http://localhost”);//ex.)https://test.co.jp
header(“Access-Control-Allow-Credentials: true”);
// --- Origin Check ---
$origin = $_SERVER[‘HTTP_ORIGIN’] ?? ‘’;
$referer = $_SERVER[‘HTTP_REFERER’] ?? ‘’;
// --- Existing key validation and image return logic starts here ---
$valid_key = “password”; // Fixed key or token check
$key = $_GET[‘key’] ?? ‘’;
$file = basename($_GET[‘file’] ?? ‘’);
if ($key !== $valid_key) {
header(“HTTP/1.1 403 Forbidden”);
exit(“Forbidden”);
}
$path = __DIR__ . “/” . $file;
if (!file_exists($path)) {
header(“HTTP/1.1 404 Not Found”);
exit(“Not Found”);
}
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $path);
finfo_close($finfo);
header(“Content-Type: $mime”);
readfile($path);
exit;
| 著作権情報 |
| ホームページおよプリ等に掲載されている情報等については、いかなる保障もいたしません。 ホームページおよびアプリ等を通じて入手したいかなる情報も複製、販売、出版または使用させたり、 または公開したりすることはできません。 当方は、ホームページおよびアプリ等を利用したいかなる理由によっての障害等が発生しても、 その結果ホームページおよびアプリ等を利用された本人または他の第三者が被った損害について 一切の責任を負わないものとします。 |