Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #####DOCUMENTATION######
- >>LONG
- This login system was coded in order to have a portable login and site protection system.
- We decided to make this happen with a class. A class is in PHP something like a blueprint for an object.
- The class itself doesn' t need to be changed in any way! You can control everything simply by changing some arguments (will be explained soon).
- In order to gain acces to the class you have to tell the PHP processor (server) that he has to look at the file.
- This documentation assumes that you have already a PHP-Site and -Server.
- We assume that the site you want to password-protect is called 'index.php' also.
- In PHP you can do this be 'require_once' a file.
- Example:
- --Make sure that you have the <?php tags!
- >>>require_once 'login.php';
- (no '>>>')
- The filename is login.php. This is the name of the file where the class is written. You can change the name or leave the default one.
- If you changed the name of the file make sure, that you change the name also in the example code line.
- Now that the server knows about the class we have to tell the server that we want to use it.
- In this step we also have to pass some arguments to the class
- Example:
- --Write this line right after the code line in Example 1!
- >>>$login = new login(array('yourpassword', $_POST['password'], 'preset'));
- (no '>>>')
- Explanation:
- First we have to "copy" the class into a object called $login. We need to do this; using the blueprint (class).
- The actually "copying" is the '=' [...]
- The keyword 'new' tells the server that we want to create a new instances of the blueprint/class.
- "login([...])" is the name of the class and tells the server to use this class.
- In the bracktes are the argumentes needed by the class.
- In order to keep the class fexilbe we deicide to pass an array to the object.
- The array contains 3 values:
- 1 Your password, the correct one
- 2 The password entered by the user
- 3 The path to the login form
- The correct password can you choose for your self! In the example files the password is 'demo'.
- The input password can be passed diffrently. To get started simply leave it as it is. If you are an advanced user you can pass everything into this.
- The path to the login form is semi-optional. If you do not want to code your own form simply type 'preset' and you' ll see the default form coded by us.
- If you have designed your own login-form make sure that you type the URL in correctly in the following format:
- 'http://example.com/form'
- Make sure that you include the http:// or https:// at the beginning of the form...
- For the form itself you only have to keep in mind the follwing aspects:
- >>><form action="index.php" method="POST">
- >>> <input name="password" />
- >>></form>
- (no '>>>')
- The action="" of the form should point to a file where the class is implemented, NOT the login.php file!
- The name of the input field for the password should be 'password' or you have to change the 2nd item in the array (where it says $_POST['password']) to whatever you name the field (e.g. $_POST['yourname']).
- If you want to use as the method GET you have to change the second item in the array (where it says $_POST['password']) to $_GET['password'], however it is NOT recommend to do this.
- The final file you want to protect should now look like that:
- >>><?php
- >>>require_once 'login.php';
- >>>$login = new login(array('yourpassword', $_POST['password'], 'preset'));
- >>>?>
- >>><!DOCTYPE html>
- >>><html lang="en-US">
- >>> <head>
- >>> <meta charset="utf-8">
- >>> <title>Secret File</title>
- >>> <link rel="stylesheet" href="">
- >>> <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
- >>> <!--[if lt IE 9]>
- >>> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
- >>> <![endif]-->
- >>> </head>
- >>>
- >>> <body>
- >>> <h1>Secret File</h1>
- >>> <p>This paragraph is hidden</p>
- >>> </body>
- >>>
- >>></html>
- (no '>>>')
- The HTML-Part is up to you. You can also write your own PHP-logic into this file, as long as these two lines are at the very top of your file.
- If you want to log out simply append '?logout' to a URL where the class is implemented:
- For example you have the file index.php (example above) and want to logout simply create a link like this:
- >>><a href="?logout">Logout</a>
- (no '>>>')
- You can also have the link pointing to any file which as the login class implemented and append '?logout', e.g.
- >>><a href="othersite.php?logout">Logout</a>
- (no '>>>')
- If you are an advanced user you can also call the function logout in order to log the user out like this:
- >>>$login->logout();
- (no '>>>')
- That' s it.
- Thanks for purchasing
- SAFE - The Login Class
- Regards,
- DaGardner
- dagardner.net
- codecanyon.net/user/DaGardner
Advertisement
Add Comment
Please, Sign In to add comment