How to limit access to the page

How to limit access to the page

If there was a need to limit access for unwanted visitors to the page of the website, then use of the system of authorization which is built in the Web server will be the simplest solution. It is below - the description how exactly it becomes.

Instruction

1. Create on the server the folder for pages which should be protected, and move them there. If you want to limit access to all pages, then this step can be passed - protection will be organized in a root folder of your website.

2. An algorithm of operations of the Apache server such is that having found in the folder the office file with a name "" .htaccess"", he uses the instructions which are contained in the file at request processing of visitors of the website on any documents of this and all enclosed folders. You need to create this file and to place in it directives of access restriction to all or separate documents of this folder. It is possible to make it at himself on the computer, having used the simple text editor, for example the Notepad. Create the empty file (CTRL + N) also enter in it these lines: AuthType Basic
AuthName ""Access to the Page Is Limited!"
AuthUserFile/usr/account/site/.htpasswd
require of a valid-userdirectiv in the first line turns on the mechanism of basic authorization (AuthType Basic). At this type of authorization the password of the visitor is transferred from the browser encrypted on algorithm Base64. The directive specifies contents of the text hint which the browser will display at the visitor's entrance to the protected part of the website in the second line. Enter the text necessary to you without using in it is mute quotes (""). The third line contains an absolute path to the file storing vapors the login: the password, access to which is allowed to pages of this folder. The login is stored in open form, and the password is encrypted. Absolute (that is from a server root) it is possible to look at path to your website in the panel of administration of the website or to learn from technical support of a hosting. And it is possible to use the phpinfo command () language RNR.Direktiva in the fourth line defines the principle of authentication. If to specify User value, then only users whose logins should be listed through a space here will be allowed. Group value - only the users belonging to groups which should be specified through a space here. If Valid-user - all users whose logins are listed in the AuthUserFile file. Naturally, at any value all these users for access should enter the correct password.

3. Save the created file under the name of .htaccess, having selected the All Files item in the File type list of a dialog of saving - it is in order that the text editor automatically did not add the txt extension.

4. Now you should create the file of passwords specified in the directive AuthUserFile - .htpasswd. It is made the htpasswd.exe utility of structure of the Apache server. It is in the bin folder to download this utility, for example, here - http://www.intrex.net/techsupp/htpasswd.exe. It is the console program, that is it is necessary to start it from the command line. In Windows XP OS it can be done so: copy htpasswd.exe in the separate folder, right-click the folder and select the Start of the Command Line Here item. In the command line it is necessary to enter: htpasswd - cm .htpasswd FirstUserModifikator "" - cm"" specifies that the new file of passwords should be created, and for encryption MD5 algorithm is used (this algorithm is used in Windows OS by default). If instead of ""m"" to specify ""d"" - the utility will use DES encryption algorithm if ""s"" - SHA algorithm and if ""p"" - the password is saved without encryption.FirstUser - it is the login of the first user in the list, replace it with necessary to you. For it the utility will ask the password after you click Enter. To add to the created file of the following user start the utility once again, but already without the letter ""c"" in the modifier.

5. Place the created .htaccess and .htpasswd files on the server of your website, having used the file control panel manager or the ftp-client. The .htaccess file should lie in one folder with the protected pages, and the .htpasswd file - in the folder, path to which you specified in the directive AuthUserFile. Usually files of passwords place in a directory, the root folder of the website located above to expel access to it from the Internet.

Author: «MirrorInfo» Dream Team


Print