Welcome Guest, Not a member yet? Register   Sign In
Userlib - User Library
#1

[eluser]Xikeon[/eluser]
Hello,

Because nearly every site needs/wants a Member/User system and so did I for my sites, so I made a library for it. I'll update when I need something, and post further versions Smile

Download Link: Click Here! (yup, tabs messed outside my code (PHP Designer 2007))

So, currently my class can do:
- Register a user
- Log in (CI session based)
- Check if logged in (CI session based)
- Forgot password (email based, new password sent to email)
- Get data from database by username (be careful, encrypted passwords could be get!)
- Get age by month

I'll explain every function and how to use them Smile

How to install
Put the code posted above in
system\application\libraries\Userlib.php

Now open
system\application\config\config.php
And search for
$config['sess_use_database']
Put that on TRUE.

Now open
system\application\config\autoload.php
Be sure that $autoload['libraries'] has all these in it:
'database', 'session', 'Userlib'

And the SQL:
Code:
CREATE TABLE `ci_sessions` (
  `session_id` varchar(40) NOT NULL default '0',
  `ip_address` varchar(16) NOT NULL default '0',
  `user_agent` varchar(50) NOT NULL,
  `last_activity` int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (`session_id`)
);

CREATE TABLE `users` (
  `id` int(11) NOT NULL auto_increment,
  `username` varchar(70) NOT NULL,
  `password` varchar(70) NOT NULL,
  `email` varchar(255) NOT NULL,
  `ip` varchar(15) NOT NULL,
  `status` enum('0','1','2','3') NOT NULL,
  PRIMARY KEY  (`id`)
);
In the user table, these are standard fields. The userlib won't work without. You can change the status though Wink I use:
0 = banned
1 = member
2 = moderator
3 = administrator


And now: The functions -> How to use!

Register
string $this->userlib->register( username, password, email [, status [, emailcheck [, ipcheck ] ] ] );

username: The username of the user
password: the password, this will be encrypted automaticly in: sha1( md5( password ) )
email: the email [for password retrieval and such]
status: (optional) the status to give the user, default = 1
emailcheck: (optional) Check if the email address has been used on a different account, default = TRUE
ipcheck: (optional) Check if the ip address has been used on a different account, default = TRUE

You echo this function, or send it save it as a variable. This way if there is an error message it will be put on your screen.

Examples of usage:
Code:
// Only required data
// This will check if my email and ip are used before
echo $this->userlib->register( "Xikeon", "mypass", "[email protected]" );

// All data
// This will check my email, but not ip
// This will make my account status 3 (administrator on my settings)
echo $this->userlib->register( "Xikeon", "mypass", "[email protected]", 3, TRUE, FALSE );

Login
boolean $this->userlib->login( username, password );

username: the username duh
password: the password duh

Example of usage:
Code:
if( $this->userlib->login( "Xikeon", "mypass" ) )
{
     echo 'You are now logged in';
} else {
     echo 'Your username and/or password is incorrect!';
}

Logged in
boolean $this->userlib->logged_in( );

Example of usage:
Code:
if( $this->userlib->logged_in( ) )
{
     echo 'You are logged in!';
} else {
     echo 'Please login to view this page!';
}

Forgot
boolean $this->userlib->forgot( email, length );

email: email of the user who forgot the password
length: length of new password which will be sent to the email

Example of use:
Code:
//create a password of 5 digits
$this->userlib->forgot( "[email protected]", 5 );

Get Data
string $this->userlib->getData( username, what );

username: the username of who you want to grab the data from
what: row name of what you want to get out of the database from the username

Example of use:
Code:
// Grab the status
echo $this->userlib->getData( "Xikeon", "status" );

Get Age
integer $this->userlib->getAge( day, month, year );

day: day of birth
month: month of birth
year: year of birth

Example of use:
Code:
// Get my age, will return: 15
echo $this->userlib->getAge( "8", "2", "1992" );


So, that was it I guess. Report any problems please. If any idea's, please PM them to me!

Greetings,
Mike.


Messages In This Thread
Userlib - User Library - by El Forum - 07-04-2007, 09:43 AM
Userlib - User Library - by El Forum - 07-04-2007, 10:27 AM
Userlib - User Library - by El Forum - 07-04-2007, 12:15 PM
Userlib - User Library - by El Forum - 07-04-2007, 12:21 PM
Userlib - User Library - by El Forum - 07-04-2007, 12:26 PM
Userlib - User Library - by El Forum - 07-04-2007, 12:31 PM
Userlib - User Library - by El Forum - 07-04-2007, 12:44 PM
Userlib - User Library - by El Forum - 07-06-2007, 12:08 AM
Userlib - User Library - by El Forum - 07-06-2007, 02:01 AM
Userlib - User Library - by El Forum - 07-06-2007, 12:00 PM
Userlib - User Library - by El Forum - 07-06-2007, 04:35 PM
Userlib - User Library - by El Forum - 07-08-2007, 07:03 AM
Userlib - User Library - by El Forum - 07-13-2007, 07:41 AM
Userlib - User Library - by El Forum - 07-13-2007, 01:19 PM
Userlib - User Library - by El Forum - 07-16-2007, 04:23 AM
Userlib - User Library - by El Forum - 07-18-2007, 08:04 AM
Userlib - User Library - by El Forum - 07-18-2007, 12:36 PM
Userlib - User Library - by El Forum - 07-19-2007, 10:09 AM
Userlib - User Library - by El Forum - 07-19-2007, 11:00 AM
Userlib - User Library - by El Forum - 07-24-2007, 10:19 AM
Userlib - User Library - by El Forum - 07-24-2007, 10:37 AM
Userlib - User Library - by El Forum - 07-24-2007, 10:46 AM
Userlib - User Library - by El Forum - 07-24-2007, 10:49 AM
Userlib - User Library - by El Forum - 07-25-2007, 01:34 AM
Userlib - User Library - by El Forum - 08-14-2007, 04:17 AM
Userlib - User Library - by El Forum - 01-07-2008, 09:28 AM
Userlib - User Library - by El Forum - 01-13-2008, 08:40 AM
Userlib - User Library - by El Forum - 01-20-2008, 03:41 PM
Userlib - User Library - by El Forum - 02-14-2008, 05:06 PM
Userlib - User Library - by El Forum - 03-15-2008, 06:46 PM
Userlib - User Library - by El Forum - 11-26-2008, 01:12 PM
Userlib - User Library - by El Forum - 12-01-2008, 09:23 AM
Userlib - User Library - by El Forum - 09-07-2009, 03:09 PM
Userlib - User Library - by El Forum - 09-08-2009, 10:13 AM



Theme © iAndrew 2016 - Forum software by © MyBB