hello
newbie in php language here and was woundering if there is a way to prevent access to a vital folder of my website from all except a certain php page . and if there is a way to do so can i just access the folders content via directory path/to/secret/folder or i have to request the data in some other way from the page (that i want to be only way to access said folder)
any detailed information about the website would be the folder i like to lock is inside htdocs (public folder) the content inside the folder i want locked is images
any help would be welcome
Check this:
I created a folder test on my beta.adisp007.ml subdomain.
After that, I created 4 files inside it: .htaccess, index.php, page.php, & allow.php.
I configured that .htaccess file so people only can access allow.php file on that folder.
If someone access except allow.php file, they will be redirected to forbidden page. http://beta.adisp007.ml/test/allow.php (you can access this page) http://beta.adisp007.ml/test/page.php (you can’t access this page & the rest inside that folder)
Its .htaccess code is same:
Order allow,deny
Deny From All
<FilesMatch "^allow\.php$">
Allow From All
</FilesMatch>
Only changed processing.php to allow.php accord to my files structure.
alright man i think i should be more clear in my question sorry for that
i have a folder which contains 4 subfolders each containing images
i want access to this folder its subfolders and files(images) denied to all except coming from a file.php so .htaccess goes inside main restriced folder .
and the .htaccess >>>path to >>> file.php would be “…/inc/file.php”
if this would be possible i wont have to use script and have to use less hits per user
As far as I understand,this is an example for what you want:
I created 4 folders inside my previous test folder: one, two, three, four, & inc
& inside inc folder I created file.php file.
So,you mean you want to forbid access to the images, but still want to view them on file.php file (for example by using <img> html tag)?
No code can do it. You can choose one choice, man.
Once you forbid access to public,then public can’t access it.
Even if you can allow file.php to access the images, but in the end you or some people that access file.php are public. The images won’t be generated.
But you can make certain people to access them, for example your IP or/and your hosting IP (file.php).
so your hosting ip(file.php) if this is possible this would do it , wouldnt it ?
the filephp would be public but the images priavte and visitors request filephp which requests images , would that be possible
Hello katufo
thanks again for the replay.
With my little knowledge i think this prevents access from certain files except requested by the given ip.
If this is the case iam afraid it will not do because in the end diffrent people will request thier images from diffrent ips and should get them (the purpose of the site)
What i specificaly want is for the folder or files inside that folder which will be jpg, jpeg or both to be inaccessable throu out typing thier mysite/path/file.jpg
But also user can only access them when requested by file.php .
Sorry if my explaining is not all that good
That’s still impossible.
I mean if you want to make only certain people to access your files, you can do it by using .htaccess, such as @katufo posted above.
But that won’t make what you want.
Even if file.php is allowed to access your images,the public still can’t view your images because their images request (by browser) are your original images URL.
This is its diagram:
But after I tried (trial&error),I can make the images viewable using .htaccess+PHP.
Continue from my post above:
For example I uploaded img1.jpg & img2.jpg inside folder one.
The code inside file.php is something like this:
you my friend are a life saver this is what i was looking for.
i have been surfing the web for a while now and posting on multiple forums
thanks for keeping up with a newbies question