Location: PHPKode > scripts > User Manager > user-manager/files/doc.html
<h1>UserManager PHP class - v1.0</h1>
<h2>Waht the class does - Main features</h2>
<p>
	<ul>
		<li>Allows user to register,</li>
		<li>to login,</li>
		<li>to edit their informations,</li>
        <li>to get their lost password back</li>
        <li>Easy handle those kind of pages on your website</li>
        <li>Only requirement: a MySQL database</li>
	</ul>
</p>

<h2>Functions in the class</h2>
<h3>check_email</h3>
<p>
	<code>
		function check_email($address)
		<br /><br />
		@param string $address  the email address to check<br />
	 	@return bool true if the email is valid, false otherwise<br />
	</code>
	<br />
	Checks if the passed email address is valid
</p>

<h3>create_password</h3>
<p>
	<code>
        function create_password($lenght = 7)
		<br /><br />
		@param int $lenght the password lenght (default 7)<br />
	    @return string the random password<br />
	</code>
	<br />
	Creates a random password using the characters specified. The lenght may be modified passing changing the parameter 'lenght'.
</p>

<h3>username_taken</h3>
<p>
	<code>
		function username_taken($username)
		<br /><br />
	    @param string $username the username<br />	  
	    @return int 0 if the username is free<br />
	</code>
	<br />
	Checks if a certain username has already been registered
</p>

<h3>add_user</h3>
<p>
	<code>
		function add_user($username, $password, $email)
		<br /><br />
	    @param string $username the username to register<br />	  
	    @param string $paswsord the encrypted password<br />	  
	    @param string $email the email to store<br />	  
	    @return mixed the query result<br />
	</code>
	<br />
    Adds the usernam e (and his informations) to the database
</p>


<h3>display_status</h3>
<p>
	<code>
		function display_status()
		<br /><br />
	    @return void<br />
	</code>
	<br />
    Displays the welcome message for new users (those just registered)
</p>

<h3>display_register</h3>
<p>
	<code>
		function display_register()
		<br /><br />  
	    @return void<br />
	</code>
	<br />
    Displays the register form and handles the user registration request
</p>

<h3>display_forgot</h3>
<p>
	<code>
		function display_register()
		<br /><br />  
	    @return void<br />
	</code>
	<br />
    Displays the password reminder form, create the random pasword and send a message to the user
</p>

<h3>display_user</h3>
<p>
	<code>
		function display_user()
		<br /><br />  
	    @return void<br />
	</code>
	<br />
    Displays the change password form and the edit user info form
</p>

<h3>display_login</h3>
<p>
	<code>
		function display_login()
		<br /><br />  
	    @return void<br />
	</code>
	<br />
    Log the user in or displays the login form
</p>


<h3>log_out</h3>
<p>
	<code>
		function display_log_out()
		<br /><br />  
	    @return void<br />
	</code>
	<br />
    Logs the user out
</p>


<h3>confirm_user</h3>
<p>
	<code>
		function confirm_user($username, $password)
		<br /><br />  
        @param string $username the username to check<br />
        @param string $password the password of the user<br />
	    @return int the status of the request<br />
	</code>
	<br />
    Checks if the user has specified the right password to access.<br />
    Returns 0 if everything is OK,
            1 in case of username failure,
            2 if the password is wrong
</p>


<h3>check_login</h3>
<p>
	<code>
		function check_login()
		<br /><br />  
	    @return bool 1 if the login is OK, else 0<br />
	</code>
	<br />
    Authenticates the user request
</p>





<h2>Examples of use</h2>
<h3>Example #1</h3>
<p>
    <code>
    include_once("usermanager.php");<br />
<br />
    UM = new UserManager;<br />
<br />
    // Change the username max length<br />
    UM->USR_MAXCHARS = 50; // Default 30<br />
<br />
    // Change the HOMEPAGE to link by default (Default "/index.php")<br />
    UM->HOMEPAGE = "http://example.org/index.php"; // may also be "../index.php"<br />
<br />
    // Change the redirection page to access after the login (Default "/index.php")<br />
    UM->REDIR_PAGE = "http://example.org/myredirection.php";<br />
<br />
    // Change the links to LOGIN|REGISTER|FORGOT PASSWORD<br />
    $UM->LOGIN|REGISTER|FORGOTPW = "a_page_on_your_site.php";<br />

	</code>
</p>

<h3>Example #2</h3>
<p>
	<code>
        include_once(usermanager.php);<br />
<br />
        UM = new UserManager();<br />
<br />
        // The URL of the page should be something like<br />
        // http://example.org/switcher.php?action=LOGIN|REGISTER|FORGOT|INFO<br />
        switch ($_GET['action'])<br />
        {<br />
         &nbsp;&nbsp;&nbsp;   case LOGIN:<br />
               &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; UM->display_login();<br />
             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  break;<br />
            &nbsp;&nbsp;&nbsp; case REGISTER:<br />
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  UM->display_register();<br />
               &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br />
            &nbsp;&nbsp;&nbsp; case FORGOT:<br />
             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   UM->display_forgot();<br />
               &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br />
            &nbsp;&nbsp;&nbsp; case INFO:<br />
               &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; UM->display_user();<br />
               &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br />
           &nbsp;&nbsp;&nbsp; default:<br />
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  // Redirects to the home page set in the class<br />
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  header("Location: $this->HOMEPAGE");<br />
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  break;<br />
        }<br />
	</code>
</p>

<h2>Changelog</h2>
<p>
	No changes made since now.
</p>

<h2>License</h2>
<p>
	Copyright (C)2007 Giulio Bai <hide@address.com>
</p>

<p>
	<blockquote>
		This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License v2 as published by the Free Software Foundation.
		<br /><br />
		This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
		<br /><br />
		You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
</blockquote>
</p>

<p>
	A copy of the full license can be found in the <a href="http://www.gnu.org/licenses/gpl.html">official GNU's site</a>
</p>

<h2>Notes</h2>
<p>
	<h3>Links</h3>
	<ul>
		<li><a href="http://hewle.com">http://hewle.com</a> - My site :)</li>
		<li><a href="http://www.phpclasses.org">http://www.phpclasses.org</a> - Lots and lots of PHP classes</li>
		<li><a href="http://www.php.net">http://www.php.net</a> - PHP official site</li>
	</ul>
	
	<h3>Plase share it!</h3>
	<p>
		If you found this program useful, share it! Maybe it can help also other people!<br />
		Don't be scared, it's free, editable, redistributable.<br />
		So... share, Share, SHARE!	
	</p>
	
	<h3>Contacts</h3>
	<p>
		If you want to know more about this program, you can contact me at <a href="mailto:hide@address.com">hide@address.com</a>.<br />
		Wht do you think about this program? Is it useful? How can be improved?	
	</p>
</p>
Return current item: User Manager