This is my index.php:
<?php
require_once('includes/settings.php');
require_once('includes/functions/images.php');
$_SESSION['userisonpage'] = true;
In the Settings-file there is the session_start and a few things like the database Connection:
<?php
error_reporting(0);
// ini_set('session.gc_maxlifetime', 180);
session_start();
Now I have an image.php that receives a GET-Parameter after a specific rewrite rule.
RewriteRule ^images/items/(.+)$ /index.php?image=$1 [L,QSA]
So far so good. The image.php checks then if there was set the $_SESSION['userisonpage']-sessionvariable before loading the image. I dont know why, but the result is always false and shows the "hotlink.jpg"-file - even if the image is loaded within the webpage.
<?php
if(isset($_GET['image'])){
$path = '/data/web/123456/html/abc/images/';
$file = trim($_GET['image']);
if(file_exists($path.'items/'.$file)){
if($_SESSION['userisonpage'] === true){
echo file_get_contents($path.'items/'.$file);
}else{
echo file_get_contents($path.'hotlink.jpg');
}
}else{
header('location: https://abc.de/');
}
die;
}
?>
EDIT #1
Ok, I found out that when I call the image with the URL
http://abc.de/images/items/test.jpg
the Session ID always is another one while when I call the same image with the URL
http://abc.de/?image=test.jpg
the Session ID stays the same.
So it seems to be a problem between Sessions and Mod Rewrite.
Edit #2:
I now found out that when I call the image with this URL
http://abc.de/images/items/test.php // <-- !!! PHP-extension !!!
and replace the .php in the get-parameter with .jpg
if(isset($_GET['image'])){
$path = '/data/web/123456/html/abc/images/';
$file = trim($_GET['image']);
$file = str_replace('.php', '.jpg', $file); // <-- replace the extension
if(file_exists($path.'items/'.$file)){
it also loads the session variable and the image as it should.