<?php
////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright EB Dynamics, Inc., Edward Lemmers, P.E.
// For licensing, see license.txt.
// Created: 4/30/2010
// Modified: 12/2/2010	Ed Lemmers
// Changed relative path to index.php to absolute path to fix problem of infinite loop back to index.php in kfm folder.
// Revised: 2/7/2012	ELL
// Added table prefix handling.
// Revised: 3/25/2013	ELL
// Security enhancements for PDO.
//
	error_reporting (E_ALL ^ E_NOTICE);
	
	session_start();
	$userid = $_SESSION['userid'];
	$curr_session = md5(session_id());
	
	include ("../../connect/db_connect.php");
	include ("../../connect/config.php");
	
	$query = "SELECT `Session`, `IP`, `AccessLevel` FROM `" . BWB_TABLE_PREFIX . "users` WHERE `UserID`=:userid";
	$stmt = $bwb_dbh->prepare($query);
	$stmt->execute(array(':userid' => $userid));
	$row = $stmt->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT);
	
	$session = $row['Session'];
	$ip = $row['IP'];
	$access_level = $row['AccessLevel'];
	$curr_ip = $_SERVER['REMOTE_ADDR'];
	
	if (($curr_session != $session) || ($curr_ip != $ip))
		header("Location: /index.php");
?>