PHP Tutorial: Developing a Login – Part 1 - Misc




Let’s have a quick look at some of the remaining methods within the authentication class, which might be of interest.

Notice that you’re required to name the session that’s going to be used for user authentication with the following method, the reasons being:

  • To avoid possibly overwriting existing sessions using the same names.
  • During logout we simply need to destroy a part of the session and not the full session, since other scripts might be using other parts of the active session.
 
public function session($session)
{
	$this->session = $session;
}
 

The next method we use to secure a page, if the user isn’t logged in, we redirect them to the login page.
 
public function secure()
{
	if (!$this->is_loggedin())	{
 	$this->redirect(VIRPATH.'/users/login.php?redirect='.urlencode($_SERVER['REQUEST_URI']));	}
}
 

This method checks if the current user is logged in.
 
public function is_loggedin() {
	return isset($_SESSION[$this->session]);
}	
 

This method simply unsets our "possible part" of the session, which logs the user out.
 
public function logout() {
	unset($_SESSION[$this->session]);
}
 




No Entries Found

Post comment

Name *
Email
Title
Body *
Security code
*
* Required fields

Latest Articles

Top 5 Articles

Programming humor


Collection of funny programming articles
2006-10-08 14:23:43

How to create your own RSS Reader


It is very simple creating your own rss reader, the following article looks at a few methods of doing this.
2008-06-23 13:18:25

Javascript Reference: Dropdown


A quick reference about working with dropdown boxes (select element) in javascript.
2007-02-17 16:36:41

PHP: Snippets


Collection of PHP snippets
2010-05-22 00:06:45

Event driven programming in PHP


An article looking at adding some kind of event driven model to PHP 5
2008-07-28 12:48:09