Question: My problem is when you use for exemple :

```
<img src="/img.jpg" />

```

the src has to be an image and the image has to be accessible to the person. I want to be able to control the access to those image (if the user is logged for example). IF the person has not access to the image, he can't access it. My script that controls the access to an image is a php file.

I know .htaccess can limit access to ressources, but I need to valid in the php file. Is there a way to do this or to load the image with javascript (using ajax request) and changing the source of the image to the location of the image in the temp folder?

Answer: 
Your image source doesn't necessarily have to point to the real image, neither does it have to be an image:

```
<img src="images.php?f=img.jpg" />

```

Then you can write a PHP script which does the required validations and return the image afterwards through the script

```
$image = basename($_GET['f']);
if (user_has_access()) {
    // You have to determine / send the appropriate MIME-type manually
    header('content-type: image/jpg');
    readfile($image);
} else {
    header('HTTP/1.1 403 Forbidden');
}

```
You can ceep user\_login\_status in your $\_SESSION, and on a view part check it

```
<?if ($_SESSION['user_status'] == 'login'){?>
  <img src="/img.jpg" />
<?}else{?>
  // some stuff instead of <img/>
<?}?>

```