newbieprog
newbieprog

Reputation: 3

How can i protect a URL/Directory in my site?

I want to protect a URL in my site For exapmle: www.mysite.com/admin using user "Login" I don't want to let anyone see any content in the "admin" directory not even a picture or any other file. How could this be possible? i have read about the sessions and all but that can stop a user to access a webpage. I am familiar with PHP. Please help!

Upvotes: 0

Views: 261

Answers (3)

Mike
Mike

Reputation: 24383

It's a little bit ugly, but the easiest way would be to password protect the directory, which would bring up an authentication pop-up type box to the browser. If you are using Apache, you can find out more information in the Apache docs. If you are using another server, they will likely have similar docs available somewhere. This can also be done directly by PHP by sending the correct header in order to authenticate against a database instead of storing the users' information in a text file.

If you are looking to make it seamlessly integrate into your site (i.e. without the ugly pop-up), it is a bit more difficult, but doable. The PHP files are easy. Just write some sort of code to determine if the user is logged in, and if not, don't show the content. However for the images or other static files, I would recommend doing something like this: Echo/print a jpg-image with php, for safety?

Upvotes: 1

Piya Pakdeechaturun
Piya Pakdeechaturun

Reputation: 141

I'm not quite sure what is your purpose so

.htaccess is the one solution to help you protect your data if the user know all specific path but this solution need some effort to learn

but if you think no one know your specific path so an quick and easy way is to create plain index.php to echo some wording to who want to access that folder in every folder you have can help you to protect the list of directory in your folder path

hope this help ;)

Upvotes: 1

Afsar
Afsar

Reputation: 3124

Take a look at this, you can hide according to your need

Upvotes: 0

Related Questions