I am struggling with PHP
login and user validation after they log on to the system. I know the basics but I'm not sure if I'm doing it right. I will try to explain it step by step.
- I have a form for user name and password.
- After users enter they login and password i'm using
LDAP
authentication to authorize them. And if authentication pass then i need to start new session. New session (and this is where i'm struggling).
if ($validation->ldap_authentication()) { $session = new session(); $session -> login($validation->getUsername(), $validation->logedAs(), $validation->getSID()); if($session->validate_login()) { exit(header('Location:index2.php')); } else { echo 'error'; } }
And my session class
:
class session
{
public function __construct()
{
if(!isset($_SESSION))
{
session_name(SESSIONNAME);
ob_start();
session_start();
} else {
session_regenerate_id(true) ;
}
}
public function login($sessionUserName, $logedAs, $sid)
{
$_SESSION['logedUserName'] = isset($sessionUserName) ? $sessionUserName : null;
$_SESSION['logedAs'] = isset($logedAs) ? $logedAs : null;
$_SESSION['sid'] = isset($sid) ? $sid : null;
}
public function validate_login()
{
if (!isset($_SESSION['logedUserName']) || (trim($_SESSION['logedUserName']) == '') ||
!isset($_SESSION['logedAs']) || (trim($_SESSION['logedAs']) == '') ||
!isset($_SESSION['sid']) || (trim($_SESSION['sid']) == '')
)
{
return false;
} else {
return true;
}
}
}
- So in the another pages i need to start a class
session
(again) and validatevalidate_login()
? - For me it looks really poor authentication.
What do I need to add and improve?
I already searched online but couldn't find an answer and don't know what exactly I need to improve.