I'm not sure about the "giving" images thing, but
If you don't want someone to access a file directly then you don't make it a file they can access directly. Put the image files somewhere not accessible by typing in a URL (meaning they don't go in your public_html or www or whatever directory where your website files go), then create a PHP script that shows the image instead - but only after it runs some other code to make sure it actually should display the image.
Basically,
<?php
// include your common header file or session_start or whatever
// figure out what image was requested
// ex: /script.php?image=whatever.jpg then $_GET["image"]
$image = $_GET["image"];
// look up whether the user can see the image
// if they can't then show a "not allowed" image instead (or maybe do something else)
if (!$user_can_see_image) {
$image = "notallowed.jpg";
}
$file = "/path/to/your/images/" . $image;
// output the image
header("Content-Type: image/jpeg"); // this changes for different types of images!
header("Content-Length: " . filesize($file));
readfile($file);
After that's in place you can worry about things like making the URL look prettier (maybe /image/whatever.jpg) or enabling caching to save you bandwidth.