Part of the EllisLab Network
   
3 of 4
3
Userlib - User Library
Posted: 24 July 2007 11:46 AM   [ Ignore ]   [ # 21 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  162
Joined  02-14-2007

Sure, so if you setup your call like this:

$user_list = $this->userauth->getData();

what you end up with an 3d array of users and their information

Array (
[0] => Array (
  
[id] => 1
  [username]
=> user1
  [password]
=> 55c3b5386c486feb662a0785f340938f518d547f
  [name]
=> name 1
  [email]
=> email1@address.com
  [ip]
=> 255.255.255.255
  [status]
=> 3
  
)
[1] => Array (
  
[id] => 2
  [username]
=> user2
  [password]
=> 55c3b5386c486feb662a0785f340938f518d547f
  [name]
=> name 2
  [email]
=> email2@address.com
  [ip]
=> 255.255.255.255
  [status]
=> 3
  
)
)

This then gives you the ability to foreach out your array as such

foreach($user_list as $user) {
  
echo $user['name'] . ' - '.$user_perm_level[$user['status']].'<br />';
}

*** one to keep in mind is that I setup the user perm level as a config item so you’ll basically want to do something like this before your foreach…

$user_perm_level = $this->config->item('user_perm_level');
 Signature 

Trying to do it right the first time! whoops guess that didn’t work out so well…

Profile
 
 
Posted: 24 July 2007 11:49 AM   [ Ignore ]   [ # 22 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  162
Joined  02-14-2007

One thing I forgot - the changes I added are for if you’re trying to list multiple users… in the case of pulling one user back - do the same thing just make sure you set your $username - and then it’ll loop though just one record since you’ve limited the return…

On a side note - I personally get a little more vague on my where clause setups in my models and build the “semi” sql in the code call that way i can customize my where statement any way I need on the fly - it’s probably not the best practice but it works for me.

 Signature 

Trying to do it right the first time! whoops guess that didn’t work out so well…

Profile
 
 
Posted: 25 July 2007 02:34 AM   [ Ignore ]   [ # 23 ]  
Grad Student
Avatar
Rank
Total Posts:  93
Joined  06-05-2007
Code Arachn!d - 24 July 2007 11:49 AM

One thing I forgot - the changes I added are for if you’re trying to list multiple users… in the case of pulling one user back - do the same thing just make sure you set your $username - and then it’ll loop though just one record since you’ve limited the return…

Check I modified the source code of Userlib with your new getData function and so far it’s working. When you say set the $username I think this is what you’re talking about?

$user_list = $this->userlib->getData($username);

foreach(
$user_list as $user )
{
echo $user['username'];
}
 Signature 

Functional PHP Extension A set of higher-order functions and other primatives written in PHP (3/4 compatible) which let you write php code in a functional style, similar to the way you might in Haskell, Scheme, or ML.

Profile
 
 
Posted: 14 August 2007 05:17 AM   [ Ignore ]   [ # 24 ]  
Summer Student
Avatar
Total Posts:  23
Joined  08-08-2007

big big thx’s smile But how logout? session_destroy?

Profile
 
 
Posted: 07 January 2008 10:28 AM   [ Ignore ]   [ # 25 ]  
Grad Student
Avatar
Rank
Total Posts:  73
Joined  02-05-2007
iniweb - 14 August 2007 05:17 AM

big big thx’s smile But how logout? session_destroy?

just put:

function logout()
    
{
        $this
->CI->session->sess_destroy();
    
}

at the end of the file
(before:

}
// END User Class
?>

)
and you’re done.

you can call it like

$this->userlib->logout();
Profile
 
 
Posted: 13 January 2008 09:40 AM   [ Ignore ]   [ # 26 ]  
Summer Student
Total Posts:  3
Joined  09-13-2007

There is an inconsistency in your class: namely, the table names are hardcoded. This is very disturbing when I set up my CI install to use table prefixes, and I expect it to be used in every library, helper, etc.

Profile
 
 
Posted: 20 January 2008 04:41 PM   [ Ignore ]   [ # 27 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  464
Joined  01-16-2008
function getData( $user, $what )
    
{
        
if(is_numeric($user))
        
{
            $lcheck
= $this->CI->db->query( "SELECT " . mysql_real_escape_string( $what ) . " FROM `user` WHERE
                                            ID='"
. mysql_real_escape_string( $user ) . "'" );
            if(
$lcheck->num_rows( ) == 1 )
            
{
                $data
= $lcheck->row( );
                return
$data->$what;
            
} else {
                
return 'User or row does not exist.';
            
}
        }
        
else
        
{
            $lcheck
= $this->CI->db->query( "SELECT " . mysql_real_escape_string( $what ) . " FROM `users` WHERE
                                            username='"
. mysql_real_escape_string( $user ) . "'" );
            if(
$lcheck->num_rows( ) == 1 )
            
{
                $data
= $lcheck->row( );
                return
$data->$what;
            
} else {
                
return 'Username or row does not exist.';
            
}
        }
    }

i added the is_numeric to the get data so you will be able to put a user id number or just put in their username and both will work in the same function! smile (the only problem is that if their username is only numbers it will cause an error. so just make it so that your users have to include a letter in thier name)

 Signature 

CodeSanity | Github | LinkedIn | Facebook | Twitter | Last.fm

Profile
 
 
Posted: 14 February 2008 06:06 PM   [ Ignore ]   [ # 28 ]  
Summer Student
Total Posts:  1
Joined  02-10-2008

Sorry for My bad English

how can user on my site view you own login (or email) at page?

echo $this->userlib->getData( “_what write this_”, “_what write this_”);

I am noob, help me please.
Thx.

Profile
 
 
Posted: 15 March 2008 07:46 PM   [ Ignore ]   [ # 29 ]  
Summer Student
Total Posts:  2
Joined  03-15-2008

Awesome, man. Thanks, it looks great!

 Signature 

MSN hacken

Profile
 
 
Posted: 26 November 2008 02:12 PM   [ Ignore ]   [ # 30 ]  
Summer Student
Total Posts:  1
Joined  11-26-2008

How about column ‘user_data’ in the ‘ci_sessions’ table?

The next error occurs when I type right login and password. In other case I see “0”.

if( $this->userlib->login( $_POST['login'], $_POST['password'] ) )
      
{
          
echo "1";
      
}
      
else
      
{
          
echo "0";     
      
}

A Database Error Occurred
Error Number: 1054

Unknown column ‘user_data’ in ‘field list’

UPDATE `ci_sessions` SET `last_activity` = ‘1227724828’, `user_data` = ‘a:2:{s:8:\“username\”;s:8:\“user1310\”;s:8:\“password\”;s:40:\“84e3ac481dd7e5360cad7225a232fffb2c94d64a\”;}’ WHERE `session_id` = ‘790c74a9c6a13cdea3a7c8d7e1327750’

When I add column ‘user_data’ in the ‘ci_sessions’ table everything is OK.
Why the author didn’t write about this or may be I do something wrong?

Profile
 
 
   
3 of 4
3
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 819, on March 11, 2010 11:15 AM
Total Registered Members: 120483 Total Logged-in Users: 20
Total Topics: 126559 Total Anonymous Users: 1
Total Replies: 665409 Total Guests: 287
Total Posts: 791968    
Members ( View Memberlist )