[PHP][DEV] Base user class
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 Users( Core $core )
{
$this->iCore = $core;
$this->searchForSessions();
}
protected function searchForSessions()
{
global $core;
$x = array('_userName', '_passWord', '_cacheData');
$y = true;
$z = md5( db::$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[ 0 ] ], $_SESSION[ $z . $x[ 1 ] ] )
->count() > 0 ? 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 = md5( db::$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.)
Re: [PHP][DEV] Base user class
This is abit too complicated for me, but I'll certainly take a look.
Re: [PHP][DEV] Base user class
Quote:
Originally Posted by
PowahAlert
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.
Re: [PHP][DEV] Base user class
How exactly do you use cacheData?
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.
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
Re: [PHP][DEV] Base user class
Quote:
Originally Posted by
joopie
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
Re: [PHP][DEV] Base user class
Quote:
Originally Posted by
joopie
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.
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.
Re: [PHP][DEV] Base user class
Quote:
Originally Posted by
Divide
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!