Location: PHPKode > projects > Cadence Guestbook Host > cadence/class/login.php
<?php

/************************************
 * Cadence
 * Remotely Hosted Guestbook Script.
 * (c) 2006, Dennis Pedrie
 * www.CadenceBook.com
 * login.php
 * Last Modified 11-30-05
 ***********************************
 * Cadence Guestbook is licensed under
 * a Creative Commons License.
 * More information is available by visiting
 * http://creativecommons.org/licenses/by/3.0/
 * or the LICENSE file in the Cadence Root Folder
 ***********************************/

/**
* Login Class. Manages all Login/Logout related functions
*
*
* @name login
* @package	Cadence Guestbook
* @author   Dennis Pedrie
* @copyright Dennis Pedrie
* @version	1.0
*/

class login {
	
	/**
	* Whether user is logged in or not. Use $gbook->logged instead.
	*
	* @var string
	* @deprecated
	*/
	var $logged = false;
	
	/**
	 * Checks login status.
	 *
	 * @name checklogin
	 * @author Dennis Pedrie
	 * @version 1.0 BUILD 1000
	 * @return boolean
	 *
	 **/
	function checklogin() {
		global $post,$db,$book,$q;
		
		//Set cookie vars.
		$email = htmlentities($post->clean_var($_COOKIE[COOKIE_PREFIX .'email']));
		$hash = $post->clean_var($_COOKIE[COOKIE_PREFIX .'hash']);
		
		$checklogin = $db->get_var($q->checklogin($email,$hash,$book));
		if($db->num_rows > 0) {
			$this->user_id = $checklogin;
			$this->is_book_owner = ($checklogin == $book) ? true : false;
			return true;
		}
			
		else {
			return false;
		}
	}
	
	/**
	 * Logs in the user once login form has been submitted
	 *
	 * @name dologin
	 * @author Dennis Pedrie
	 * @version 1.0 BUILD 1000
	 * @param string E-Mail
	 * @param string Raw Password
	 * @return boolean
	 *
	 **/
	function dologin($email,$pass) {
		global $db,$book,$q;

		$gethash = $db->get_var($q->gethash($email,$pass,$book));
		$displayname = $db->get_var($q->dologin($email,$pass,$book));
		if($db->num_rows > 0) {
			setcookie(COOKIE_PREFIX ."email","$email",time()+60*60*24*15,"/");
			setcookie(COOKIE_PREFIX ."hash","$gethash",time()+60*60*24*15,"/");
			setcookie(COOKIE_PREFIX ."display_name","$displayname",time()+60*60*24*15,"/");
			return true;
		}
		else {
			return false;
		}		
	}
	
	/**
	 * Handles logout. Destroys cookies, then returns to the homepage.
	 *
	 * @name dologout
	 * @author Dennis Pedrie
	 * @version 1.0 BUILD 1000
	 * @return string
	 *
	 **/
	function dologout() {
		global $book;
		setcookie(COOKIE_PREFIX ."email","",time() - 3600,"/");
		setcookie(COOKIE_PREFIX ."hash","",time() - 3600,"/");
		setcookie(COOKIE_PREFIX ."display_name","",time() - 3600,"/");
		return header("location: index.php?book=". $book);
	}
}

?>
Return current item: Cadence Guestbook Host