MrMuler Posted April 15, 2007 Share Posted April 15, 2007 hi. How can i prevent the direct viewing of an image or php file. I tried to resolve it with that: if ( $PHP_SELF == "../../index.php" ) { displayContent(); } else { displayError(); } but it doesnt work.... if somebody knows how i can restrict the direct access to files or images with .htaccess or php to restrict direct access to the file.... please let me know!! Link to comment https://forums.phpfreaks.com/topic/47101-help-how-can-i-prevent-the-direct-viewing-of-an-image-or-php-file/ Share on other sites More sharing options...
rameshfaj Posted April 15, 2007 Share Posted April 15, 2007 direct access means many things. If u want some one to enter some authentication before viewing those files,u can use the session or cookies. Link to comment https://forums.phpfreaks.com/topic/47101-help-how-can-i-prevent-the-direct-viewing-of-an-image-or-php-file/#findComment-229770 Share on other sites More sharing options...
ignace Posted April 15, 2007 Share Posted April 15, 2007 I always use the joomla solution <?PHP // main page define('_CONSTANT', 0x0001); // fancy way for setting something to true // page which should not be accessed directly but is included on the main page defined('_CONSTANT') or exit('FATAL ERROR: You are not authorized to access this file directly.'); ?> Link to comment https://forums.phpfreaks.com/topic/47101-help-how-can-i-prevent-the-direct-viewing-of-an-image-or-php-file/#findComment-229776 Share on other sites More sharing options...
neel_basu Posted April 15, 2007 Share Posted April 15, 2007 Please Clarify What do you Mean by DIRECT VIEWING Link to comment https://forums.phpfreaks.com/topic/47101-help-how-can-i-prevent-the-direct-viewing-of-an-image-or-php-file/#findComment-229834 Share on other sites More sharing options...
MrMuler Posted April 15, 2007 Author Share Posted April 15, 2007 direct view, is when you see the file or image directly.... for example: an image... Indirect view is like this: <html> ...... ...... <body> <img scr="Smileys/default/shocked.gif"> </body> </html> You'll see the image in the page! just like this a Direct view is when you want to access to an image like this: <html> ...... ...... <body> <a href="Smileys/default/shocked.gif">Direct Image</a> </body> </html> so if you click http://www.phpfreaks.com/forums/Smileys/default/shocked.gif, you'll view the image directly With php is the same concept, Indirect is when you see the page in a iframe, or its included in another page... and Direct is when you see the original file! Link to comment https://forums.phpfreaks.com/topic/47101-help-how-can-i-prevent-the-direct-viewing-of-an-image-or-php-file/#findComment-229870 Share on other sites More sharing options...
neel_basu Posted April 16, 2007 Share Posted April 16, 2007 With php is the same concept, Indirect is when you see the page in a iframe, or its included in another page... and Direct is when you see the original file!No its also direct access. Indirect Access is not that what you want. when a php scripts outputs the image with MIME Type image/png or image/jpeg or image/gif or others then it may be called as an indirect access.Cause access to that image can be controled by that php script. Link to comment https://forums.phpfreaks.com/topic/47101-help-how-can-i-prevent-the-direct-viewing-of-an-image-or-php-file/#findComment-230154 Share on other sites More sharing options...
HeyRay2 Posted April 16, 2007 Share Posted April 16, 2007 Perhaps you are looking for something like this? http://www.thesitewizard.com/archive/protectimages.shtml Link to comment https://forums.phpfreaks.com/topic/47101-help-how-can-i-prevent-the-direct-viewing-of-an-image-or-php-file/#findComment-230164 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.