Guest User

SAFE - The Login Class: Documenation LONG

a guest
Mar 10th, 2013
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.72 KB | None | 0 0
  1. #####DOCUMENTATION######
  2. >>LONG
  3.  
  4.  
  5. This login system was coded in order to have a portable login and site protection system.
  6. We decided to make this happen with a class. A class is in PHP something like a blueprint for an object.
  7. 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).
  8.  
  9. In order to gain acces to the class you have to tell the PHP processor (server) that he has to look at the file.
  10.  
  11. This documentation assumes that you have already a PHP-Site and -Server.
  12. We assume that the site you want to password-protect is called 'index.php' also.
  13.  
  14. In PHP you can do this be 'require_once' a file.
  15.  
  16. Example:
  17. --Make sure that you have the <?php tags!
  18.  
  19. >>>require_once 'login.php';
  20. (no '>>>')
  21.  
  22. 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.
  23. If you changed the name of the file make sure, that you change the name also in the example code line.
  24.  
  25. Now that the server knows about the class we have to tell the server that we want to use it.
  26. In this step we also have to pass some arguments to the class
  27.  
  28. Example:
  29. --Write this line right after the code line in Example 1!
  30.  
  31. >>>$login = new login(array('yourpassword', $_POST['password'], 'preset'));
  32.  
  33. (no '>>>')
  34.  
  35. Explanation:
  36.  
  37. First we have to "copy" the class into a object called $login. We need to do this; using the blueprint (class).
  38. The actually "copying" is the '=' [...]
  39. The keyword 'new' tells the server that we want to create a new instances of the blueprint/class.
  40. "login([...])" is the name of the class and tells the server to use this class.
  41. In the bracktes are the argumentes needed by the class.
  42. In order to keep the class fexilbe we deicide to pass an array to the object.
  43. The array contains 3 values:
  44. 1 Your password, the correct one
  45. 2 The password entered by the user
  46. 3 The path to the login form
  47.  
  48. The correct password can you choose for your self! In the example files the password is 'demo'.
  49. 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.
  50. 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.
  51.  
  52. If you have designed your own login-form make sure that you type the URL in correctly in the following format:
  53. 'http://example.com/form'
  54. Make sure that you include the http:// or https:// at the beginning of the form...
  55.  
  56. For the form itself you only have to keep in mind the follwing aspects:
  57.  
  58. >>><form action="index.php" method="POST">
  59. >>> <input name="password" />
  60. >>></form>
  61.  
  62. (no '>>>')
  63.  
  64. The action="" of the form should point to a file where the class is implemented, NOT the login.php file!
  65. 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']).
  66. 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.
  67.  
  68. The final file you want to protect should now look like that:
  69.  
  70. >>><?php
  71. >>>require_once 'login.php';
  72. >>>$login = new login(array('yourpassword', $_POST['password'], 'preset'));
  73. >>>?>
  74. >>><!DOCTYPE html>
  75. >>><html lang="en-US">
  76. >>> <head>
  77. >>> <meta charset="utf-8">
  78. >>> <title>Secret File</title>
  79. >>> <link rel="stylesheet" href="">
  80. >>> <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
  81. >>> <!--[if lt IE 9]>
  82. >>> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
  83. >>> <![endif]-->
  84. >>> </head>
  85. >>>
  86. >>> <body>
  87. >>> <h1>Secret File</h1>
  88. >>> <p>This paragraph is hidden</p>
  89. >>> </body>
  90. >>>
  91. >>></html>
  92.  
  93. (no '>>>')
  94.  
  95. 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.
  96.  
  97. If you want to log out simply append '?logout' to a URL where the class is implemented:
  98.  
  99. For example you have the file index.php (example above) and want to logout simply create a link like this:
  100. >>><a href="?logout">Logout</a>
  101.  
  102. (no '>>>')
  103.  
  104. You can also have the link pointing to any file which as the login class implemented and append '?logout', e.g.
  105.  
  106. >>><a href="othersite.php?logout">Logout</a>
  107.  
  108. (no '>>>')
  109.  
  110. If you are an advanced user you can also call the function logout in order to log the user out like this:
  111.  
  112. >>>$login->logout();
  113.  
  114. (no '>>>')
  115.  
  116. That' s it.
  117.  
  118.  
  119.  
  120.  
  121. Thanks for purchasing
  122.  
  123. SAFE - The Login Class
  124.  
  125.  
  126. Regards,
  127.  
  128. DaGardner
  129. dagardner.net
  130. codecanyon.net/user/DaGardner
Advertisement
Add Comment
Please, Sign In to add comment