forumuser Posted March 18, 2007 Share Posted March 18, 2007 Hi, I have made a simple login page to protect my photos. But then I realized that people can still access the photos by typing their path in url. http://myhost/image.jpg Is there a way to make it so that only the people who login have access to the photos? Link to comment https://forums.phpfreaks.com/topic/43200-file-access/ Share on other sites More sharing options...
per1os Posted March 18, 2007 Share Posted March 18, 2007 Setup an .htaccess file with a mod_rewrite, redirect all requests for .jpg to a jpegprocess.php file. In this file you check if the user is logged in, if they are you display the image similiar to this code: <?php if ($isLoggedIn) { $image = 'images.jpg'; // somehow get the image out of the url probably using $_SERVER variables }else { $image = 'no-access.jpg'; } $file_extension = strtolower(substr(strrchr($image,"."),1)); switch ($file_extension) { case "gif": $ctype="image/gif"; break; case "png": $ctype="image/png"; break; case "jpe": case "jpeg": case "jpg": $ctype="image/jpg"; break; } if (!file_exists($image)) { die("NO FILE HERE"); } header("Content-Type: $ctype"); header("Content-Length: ".@filesize($filename)); @readfile("$image") or die("File not found."); ?> Link to comment https://forums.phpfreaks.com/topic/43200-file-access/#findComment-209769 Share on other sites More sharing options...
forumuser Posted March 18, 2007 Author Share Posted March 18, 2007 So I never used .htaccess so don't know how to do it. Can you post a link to a good tutorial? From what I could find: Redirect 301 http://me.myhost.com/test/test/*\.jpg http://me.myhost.com/test/login.php Redirect 301 http://me.myhost.com/test/test/*\.gif http://me.myhost.com/test/login.php doesn't work Link to comment https://forums.phpfreaks.com/topic/43200-file-access/#findComment-210218 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.