Location: PHPKode > projects > Kwalbum > kwalbum/pages/LoginPage.php
<?php

/*
 * Created on Aug 19, 2008
 * 2.0
 */
require_once 'include/IPage.php';

class LoginPage implements IPage
{
	private $error;

	function LoginPage()
	{
		global $DB;
		$this->error = 0;
		if (isset($_POST['act']))
		{
			$name = $DB->FilterString($_POST['name']);
			$userPassword = $_POST['password'];
			$loginLength = (int)$_POST['length'];
			$query = 'SELECT UserId, UserIsAdmin, UserCanAdd, UserCanView
					FROM ' . USER_TABLE . "
					WHERE UserName='$name' AND UserPassword='".sha1($userPassword)."'";
			$result = $DB->query($query);
			if (0 < $result->num_rows)
			{
				$myrow = $result->fetch_array(MYSQLI_ASSOC);
				$userId = $myrow['UserId'];
				if ($userIsAdmin = $myrow['UserIsAdmin'])
					$userCanAdd = $userCanView = $userIsAdmin;
				else
					if ($userCanAdd = $myrow['UserCanAdd'])
						$userCanView = $userCanAdd;
					else
						$userCanView = $myrow['UserCanView'];
				$DB->UpdateSingle(USER_TABLE, 'UserVisitDt', 'NOW()', "UserId='$userId'");

				if ($loginLength != 0)
					setcookie(COOKIE_NAME,
						sha1($userPassword).",$userId",
						time() + $loginLength,
						'/');

				session_start();
				$_SESSION[PAGE_URL . 'id'] = $userId;
				$_SESSION[PAGE_URL . 'admin'] = $userIsAdmin;
				$_SESSION[PAGE_URL . 'add'] = $userCanAdd;
				$_SESSION[PAGE_URL . 'view'] = $userCanView;
				session_write_close();
			}
			else
				$this->error = 1;
		}
	}
	function GetHead(& $title)
	{
		$title = 'Login';
	}

	function ShowBody()
	{
		global $URLP;
		if (USER_ID)
		{
			echo '<p class="error">You are logged in and can continue <a href="'.$URLP->GetExtendedURL().'">browsing</a>.</p>';
			return;
		}

		$error = $this->error;
		require 'LoginPage.html.php';
	}
}
?>
Return current item: Kwalbum