Your IP : 216.73.216.40


Current Path : /var/www/html/mmishra/iws8/html/indem/sip/
Upload File :
Current File : /var/www/html/mmishra/iws8/html/indem/sip/init.inc.php

<?php
//include configuration and function library
require("config.inc.php");
require("functions.inc.php");

//call database connection
dbConnect("sis");

//some enumerated values
$statuss = array('active','inactive');

$referer = $_SERVER['HTTP_REFERER'];
$url = $_SERVER['REQUEST_URI'];
$remoteip = $_SERVER["REMOTE_ADDR"];

//initialize session variables and session
session_start();

if (isset($HTTP_SESSION_VARS['user'])) {
        //check session and session variables        
        $sessionid = $HTTP_SESSION_VARS['sessionid'];
        $user = $HTTP_SESSION_VARS['user'];
	$role = $HTTP_SESSION_VARS['role'];

} else if (isset($_POST['login'])) { //authenticate sign in
        $user = $_POST["txtID"];
        $pwd = $_POST["txtPWD"];
        
   	if (ldapAuth($user, $pwd) == TRUE)
		$role = localAuth($user, $pwd);
	else
		$role = 'guest';

	if ($role == 'guest') {
	        header("Location: /guest/");
	} else {
		$sessionid = base64_encode($user.'-'.$pwd);
        	$_SESSION["user"] = "$user";
        	$_SESSION["role"] = "$role";
	        $_SESSION["sessionid"] = "$sessionid";
        	//session information
	        $tbl = 'websessions';
        	mysql_query("insert into $tbl(userid,remoteip,action,datesession)
	        values('$user','$remoteip','login',now())");

		if ($role == 'admin') {
	        	header("Location: /admin/");
		} else if ($role == 'operator') {
	        	header("Location: /operator/");
	        } else {
			header("Location: /user/");
		}
	}
}

if ($_REQUEST['logout'] == 1) { //check for sing out signal
        //session information
        $tbl = 'websessions';
        mysql_query("insert into $tbl(userid,remoteip,action,datesession)
        values('$user','$remoteip','logout',now())");

        //reset session variables
        $HTTP_SESSION_VARS['user'] = "";
        $HTTP_SESSION_VARS['role'] = "";
        $user = "";
        $role = "";

	//finally destroy current session
	session_destroy();
	header("Location: /");
}
//session_destroy();

//log activity in access log database
accessLog($user, $referer, $url, $remoteip);

$header = "<html>
<head>
<title>SIP</title>
<link href='/css/style.css' rel='stylesheet' />
</head>
<body>
<center>
<img src='/images/iLogo.png' width='50' height='55' border='0' />
<h1>Indian Institute of Information Technology Allahabad</h1>
<h2>(Student Information Portal)</h2>
</center>
";
if ($user) $header .= "<div align='right'>
Welcome! $user ($role), please [ <a href='?logout=1'>Logout</a> ] here.
</div>
";
$header .= "<form method='POST' action='$PHP_SELF'>";

$footer = '</form>
</body>
</html>';

?>