PHP Classes Problem!
Moderator: General Moderators
-
cashflowtips
- Forum Newbie
- Posts: 22
- Joined: Tue Jul 31, 2007 11:06 pm
PHP Classes Problem!
I'm new to PHP but i've been exposed to many other programming languages like C++, Java and etc. I'm having a problem building a classes using PHP. I want to build a module (a group of classes) for authentication (username/password). the main problem here is, how can i build a module which can be used in any system without changing anything on the module itself? in other word is, i want to build a reusable login module that can be used for any system without changing anything on the module. can anyone answer the question or give some example on how to develop this system? thanks. 
feyd | Please use [/syntax]
then in you login pages
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Are you trying to do like a single sign on????
You could create a set of tables that any of your application could use, something similar to this
[syntax="sql"]
CREATE TABLE `application` (
`appid` int(11) NOT NULL auto_increment,
`appname` varchar(255) NOT NULL,
PRIMARY KEY (`appid`)
CREATE TABLE `user` (
`userid` int(10) unsigned NOT NULL auto_increment,
`username` varchar(30) NOT NULL,
`password` varchar(30) default NULL,
`fullname` varchar(50) default NULL,
PRIMARY KEY (`userid`),
UNIQUE KEY `username_uni` (`username`)
)
CREATE TABLE `user_app` (
`appid` int(10) unsigned NOT NULL,
`userid` int(10) unsigned NOT NULL,
`credential` varchar(30) default NULL,
PRIMARY KEY (`appid`,`userid`)
)
Code: Select all
class User
{
var $userid;
var $username;
var $password;
var $fullname;
}
class UserAuth
{
function isValid($username,$password,$appname)
{
//get user info from sql
if (found)
return new User('data from sql');
else
return false;
}
}then in you login pages
Code: Select all
UserAuth::isValid($username,$password,'APPLICATION_1');feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]-
cashflowtips
- Forum Newbie
- Posts: 22
- Joined: Tue Jul 31, 2007 11:06 pm
The process would have to be as follows:
- user requests login with username/password
- login is correct, but password is expired
- user sees message, that password has expired on change-password screen(!) and can enter his old and new password
- the user is forwarded to the requested page.
the major concern here is when the page redirect to change-password screen, how the module suppose to know which page to go without changing anything on the module...? because i want to make it re-usable over and over again to any system without to change anything inside the module...
- user requests login with username/password
- login is correct, but password is expired
- user sees message, that password has expired on change-password screen(!) and can enter his old and new password
- the user is forwarded to the requested page.
the major concern here is when the page redirect to change-password screen, how the module suppose to know which page to go without changing anything on the module...? because i want to make it re-usable over and over again to any system without to change anything inside the module...
-
cashflowtips
- Forum Newbie
- Posts: 22
- Joined: Tue Jul 31, 2007 11:06 pm
feyd | Please use
how can i put the session on this code so that from this module, the session will keep continue until the user logout or limit specific time if the user idle?
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
i alredy got the idea on how to solve the problem which is : to create an outside parameter - a define in the config or and argument of the calling handler functionCode: Select all
// some included config.php
define("MEMBER_CHANGE_PWD"."http://...");
define("MEMBER_REDIRECT"."http://...");
define("LOGIN_OK","0");
define("LOGIN_FAILED","-1");
define("LOGIN_CHANGE","1");Code: Select all
// A member class functions
function fnLogin(SOME PARAMS){
$intLogin=$this->fnCheckLogin();
if (LOGIN_CHANGE==$intLogin){
header("Location:MEMBER_CHANGE_PWD");
exit;
} elseif (LOGIN_FAILED==$intLogin){
header("Location:MEMBER_LOGIN_FAILED");
exit;
} else (
// Login OK! do your work
}
}feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]