< ?php
class login{

	private $user = '';
	private $pass = '';

	/**
	 * login::__construct()
	 * @access public
	 */
	public function __construct(){
		session_name('login');
		session_start();
	}

	/**
	 * login::set_user()
	 * @access public
	 * @param string $user
	 * @return
	 */
	public function set_user($user){
		$this->user = $user;
	}

	/**
	 * login::set_pass()
	 * @access public
	 * @param string $pass
	 * @return
	 */
	public function set_pass($pass){
		$this->pass = $pass;
	}

	/**
	* @access public
	* @return bool
	* @return redirect
	*/
	public function is_logged_in(){
		if(isset($_SESSION['is_logged_in']) && $_SESSION['is_logged_in']== true){
			return true;
		}

		return false;
	}

	/**
	* Löscht Cookie und Session
	* @access public
	*/
	public function do_logout(){
		// Cookie clientseitig löschen
		if (isset ($_COOKIE[session_name ()]))
		{
			setcookie (session_name (), '', time ()-42000, '/');
		}
		// Cookie serverseitig löschen
		session_destroy ();
		$_COOKIE = null;
		$_SESSION = null;
	}

	/**
	* Login function
	* @access public
	* @param string $user Bentuzername
	* @param string $password Passwort
	* @return bool
	*/
	public function do_login($user,$password){
		if($user === $this->user && $password === $this->pass){
			$_SESSION['is_logged_in'] = true;
			return true;
		}

		$_SESSION['is_logged_in'] = false;
		return false;
	}
}
?>
< ?php
require_once "../classes/login.class.php";
$login = new login();
$login->set_user('admin');
$login->set_pass('admin');

if(isset($_GET['logout']) && $_GET['logout']==1){
	$login->do_logout();
}

if(isset($_POST['user'])){
	$login->do_login($_POST['user'],$_POST['pass']);
}

if($login->is_logged_in()== false){
	echo 'logged out';
	?>
< form action="" method="post" >
User: < input type="text" name="user" value="" / >< br / >
Pass: < input type="password" name="pass" value="" / >< br / >
< input type="submit" value="login" / >
< /form > < ?php } else { echo 'logged in'; ?> < br / >< br / >< a href="?logout=1">Logout< /a > < ?php } ?> < br />< br />< a href="">Reload page< /a >