Welcome to the RaGEZONE - MMORPG development forums.

[PHP][DEV] Base user class

This is a discussion on [PHP][DEV] Base user class within the Habbo Releases forums, part of the Habbo Hotel category; I'm currently developing a Habbo CMS. (no promising that it will be released). I have just this second finished creating ...

LyncusMU
Page 1 of 3 123 LastLast
Results 1 to 15 of 31
  1. #1
    Account Upgraded | Title Enabled!
    Rank
    Member +
    Join Date
    May 2008
    Posts
    820
    Liked
    149

    thumbs up [PHP][DEV] Base user class

    Tabo Hotel
    I'm currently developing a Habbo CMS. (no promising that it will be released).

    I have just this second finished creating the user class; it has logging in and sessions completely finished.. I would love for some feedback on how I could improve..

    PHP Code:

    <?php

        
    class Users
        
    {
            
            public 
    $loggedIn false,
                   
    $id 0,
                   
    $userName 'Guest',
                   
    $data '',
                   
    $iCore;
                   
            
            public function 
    UsersCore $core )
            {
                
                
    $this->iCore $core;
                
                
    $this->searchForSessions();
                
            }
            
            protected function 
    searchForSessions()
            {
                
                global 
    $core;
                
                
    $x = array('_userName''_passWord''_cacheData');
                
    $y true;
                
    $z md5db::$prefix );
                
                
                foreach( 
    $x as $q )
                {
                    
                    if( empty( 
    $_SESSION$z $q ] ) )
                    {
                                            
                        
    $y false;
                        
                        break;
                        
                    }
                    
                }
                
                if( !
    $y )
                {
                    
                    return 
    false;
                    
                }
                
                        
                
    $this->loggedIn = (bool) 
                                   
    $this->iCore->db()
                                   ->
    newQuery()
                                   ->
    Query("SELECT null FROM users WHERE username = ? AND password = ? LIMIT 1;")
                                   ->
    bind('ss'$_SESSION$z $x] ], $_SESSION$z $x] ] )
                                   ->
    count() > true false;
                            
                
    $this->data $_SESSION$z '_cacheData' ];
                
                return 
    $this->loggedIn;
                
                
            }
            
            public function 
    login$u ''$p '' )
            {
                
    //p:r
                
    if( !$u || !$p ) return 'All fields are required';
                
                
    $fetch $this->iCore->db()
                              ->
    newQuery()
                              ->
    Query("
                                  
                                        SELECT 

                                            u.*, b.expire, b.reason

                                        FROM 

                                            users AS u 
                                            
                                        LEFT JOIN 
                                        
                                            bans AS b 
                                         
                                        ON 
                                        
                                            ( u.username = b.value OR b.value = ? ) AND ( UNIX_TIMESTAMP() - b.expire < 0 )

                                        WHERE

                                            u.username = ?

                                        AND 

                                            u.password = ?
                                            
                                        LIMIT 1;

                                      "
    )
                              ->
    bind'sss'$_SERVER['REMOTE_ADDR'], $u$p )  
                              ->
    fetch();
                
                
    $x md5db::$prefix );
                
                if( !empty( 
    $fetch['reason'] ) || !empty( $fetch['expire'] ) )
                {
                    
                    
    //p:r
                    
    return sprintf'You are banned until %s because %s'date'd/m/Y h:i'$fetch['expire'] ), $fetch['reason'] );
                    
                }
                
                
    $_SESSION$x '_userName' ] = $fetch['username'];
                
    $_SESSION$x '_passWord' ] = $fetch['password'];
                
    $_SESSION$x '_cacheData' ] = $fetch;
                
                
    header('Location: /');
                            
            }
            
            
        }
    FYI, this is complete with user banning etc.

    (feel free to leech.)

  2. HostKey.com: Unmetered Dedicated servers in the Netherlands
  3. #2
    Now 35% cooler!
    Rank
    Alpha Member
    Join Date
    Oct 2008
    Location
    United Kingdom
    Posts
    2,071
    Liked
    353

    Re: [PHP][DEV] Base user class

    This is abit too complicated for me, but I'll certainly take a look.
    Pure and AmirZ like this.

  4. #3
    Account Upgraded | Title Enabled!
    Rank
    Member +
    Join Date
    May 2008
    Posts
    820
    Liked
    149

    Re: [PHP][DEV] Base user class

    Quote Originally Posted by PowahAlert View Post
    This is abit too complicated for me, but I'll certainly take a look.
    Just break it down, method by method. that's what I would suggest.

  5. #4
    Now 35% cooler!
    Rank
    Alpha Member
    Join Date
    Oct 2008
    Location
    United Kingdom
    Posts
    2,071
    Liked
    353

    Re: [PHP][DEV] Base user class

    How exactly do you use cacheData?

  6. #5
    Developer & Designer
    Rank
    Member +
    Join Date
    Feb 2010
    Location
    Planet Earth
    Posts
    549
    Liked
    266

    Re: [PHP][DEV] Base user class

    Didn't know you were still working on it. ^^

    I don't think anyone here could understand every line in that class, but to me it seems pretty good. No suggestions.

  7. #6
    PHP, HTML5, CSS3, JS, C#
    Rank
    Alpha Member
    Join Date
    Jun 2010
    Location
    The Netherlands
    Posts
    1,814
    Liked
    1013

    Re: [PHP][DEV] Base user class

    In the constructor you set the core class as variable and in the search session etc you call the core var from the global :P

    Can you post it on pastebin? I cant scroll down with my phone :(
    Posted via Mobile Device
    Pure likes this.

  8. #7
    Account Upgraded | Title Enabled!
    Rank
    Member +
    Join Date
    May 2008
    Posts
    820
    Liked
    149

    Re: [PHP][DEV] Base user class

    Quote Originally Posted by joopie View Post
    In the constructor you set the core class as variable and in the search session etc you call the core var from the global :P

    Can you post it on pastebin? I cant scroll down with my phone :(
    Posted via Mobile Device
    Touche, I will change that now..

    <?php class Users { public $loggedIn = false, - Pastebin.com

  9. #8
    Developer & Designer
    Rank
    Member +
    Join Date
    Feb 2010
    Location
    Planet Earth
    Posts
    549
    Liked
    266

    Re: [PHP][DEV] Base user class

    Quote Originally Posted by joopie View Post
    In the constructor you set the core class as variable and in the search session etc you call the core var from the global :P

    Can you post it on pastebin? I cant scroll down with my phone :(
    Posted via Mobile Device
    Damn, you got a nice eye.

  10. #9
    Account Upgraded | Title Enabled!
    Rank
    Member +
    Join Date
    Aug 2011
    Location
    England Coder<3
    Posts
    525
    Liked
    104
    This is a good script. Maybe you could use cookies?

    PHP Code:
    <?php
    setcookie
    ('username'$usernametime()+60*60*24*100);
    print 
    $_COOKIE['username'];
    ?>
    Sent from my mobile via Tapatalk.

  11. #10
    PHP, HTML5, CSS3, JS, C#
    Rank
    Alpha Member
    Join Date
    Jun 2010
    Location
    The Netherlands
    Posts
    1,814
    Liked
    1013
    Quote Originally Posted by Divide View Post
    This is a good script. Maybe you could use cookies?

    PHP Code:
    <?php
    setcookie
    ('username'$usernametime()+60*60*24*100);
    print 
    $_COOKIE['username'];
    ?>
    Sent from my mobile via Tapatalk.
    Cookies only goos for 'remember me'
    Posted via Mobile Device
    At0m and AmirZ like this.

  12. #11
    Account Upgraded | Title Enabled!
    Rank
    Member +
    Join Date
    Aug 2011
    Location
    England Coder<3
    Posts
    525
    Liked
    104
    Quote Originally Posted by joopie View Post
    Cookies only goos for 'remember me'
    Posted via Mobile Device
    Yes, He could code it into the CMS.

    Sent from my mobile via Tapatalk.

  13. #12
    Works @Duck Hosts (siggy)
    Rank
    Member +
    Join Date
    Dec 2010
    Location
    Australia
    Posts
    1,252
    Liked
    529

    Re: [PHP][DEV] Base user class

    I believe this is in the wrong section, that's just me. Maybe you're just here to show off.

  14. #13
    Account Upgraded | Title Enabled!
    Rank
    Member +
    Join Date
    Aug 2011
    Location
    England Coder<3
    Posts
    525
    Liked
    104
    Quote Originally Posted by Quackster View Post
    I believe this is in the wrong section, that's just me. Maybe you're just here to show off.
    Its not a development... its him asking for improvements and giving his work out. Which I guess is called releasing ?

    Sent from my mobile via Tapatalk.

  15. #14
    Programmer
    Rank
    Member +
    Join Date
    Jan 2011
    Location
    home.php
    Posts
    273
    Liked
    72
    Quote Originally Posted by joopie View Post
    In the constructor you set the core class as variable and in the search session etc you call the core var from the global :P

    Can you post it on pastebin? I cant scroll down with my phone :(
    Posted via Mobile Device
    is that wrong :/ , cause I code the same way sometimes?
    Posted via Mobile Device

  16. #15
    Works @Duck Hosts (siggy)
    Rank
    Member +
    Join Date
    Dec 2010
    Location
    Australia
    Posts
    1,252
    Liked
    529

    Re: [PHP][DEV] Base user class

    Quote Originally Posted by Divide View Post
    Its not a development... its him asking for improvements and giving his work out. Which I guess is called releasing ?

    Sent from my mobile via Tapatalk.
    If it's a release, let me see you use it then!

    EDIT: Yes it is a development [DEV] at the top!

 

 
Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •