-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
143 lines (140 loc) · 4.69 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<!--
/*
* Copyright (C) 2014 Ashish Kedia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* This file is a part of TAJ Online Judge, developed
* @National Institute of Technology Karnataka, Surathkal
*/
-->
<?php
session_start();
$pathpre="";
if(isset($_SESSION["userid"]))
{
header('Location: dashboard.php');
}
if(isset($_POST["loginid"]))
{
include 'authentication/dbconnection.php';
$loginid = mysql_real_escape_string($_POST["loginid"]);
$password = md5(mysql_real_escape_string($_POST["password"]));
$query="SELECT * FROM taj_users WHERE userid='$loginid' AND password='$password'";
$queryres = mysql_query($query);
if(mysql_num_rows($queryres)==1)
{
$resultarray = mysql_fetch_array($queryres);
if($resultarray["islogin"]==1)
{
$query = "UPDATE `taj_users` SET `islogin`=0";
mysql_query($query);
$message=5;
}
else
{
$_SESSION['userid'] = $resultarray['userid'];
$_SESSION['type'] = $resultarray['type'];
$_SESSION['name'] = $resultarray['name'];
date_default_timezone_set('Asia/Calcutta');
$currtime = date("Y-m-d H:i:s");
$query = "UPDATE `taj_users` SET `last_login`='$currtime', `islogin`=1, `last_ip`='".$_SERVER['REMOTE_ADDR']."' WHERE `userid`='".$_SESSION['userid']."'";
mysql_query($query);
header('Location: dashboard.php');
}
}
else
{
$message=2;
}
}
if(isset($_REQUEST["message"]))
{
$message = $_REQUEST["message"];
unset($_REQUEST['message']);
}
?>
<html>
<head>
<meta charset="UTF-8">
<link rel="icon" type="image/png" href="items/crown250.png">
<link rel="stylesheet" href="style/login.css">
<link rel="stylesheet" href="style/templates.css">
<title>TAJ - Teaching Assisting Judging</title>
<script type="text/javascript">
function check_form()
{
var id = document.forms["taj_login_form"]["login"].value;
if(id==="")
{
alert("Please Enter Your Login ID");
return false;
}
var pass = document.forms["taj_login_form"]["password"].value;
if(pass==="")
{
alert("Please Enter Your Password");
return false;
}
return true;
}
</script>
</head>
<body class="taj_login">
<?php include 'templates/header.php';?>
<form method="post" action="" class="login" id="taj_login_form" onsubmit="return check_form()">
<p>
<label for="login">User ID:</label>
<input type="text" name="loginid" id="login" maxlength="50">
</p>
<p>
<label for="password">Password:</label>
<input type="password" name="password" id="password" maxlength="32">
</p>
<p class="login-submit">
<button type="submit" class="login-button">Login</button>
</p>
</form>
<div class="taj_signup_div">
<a href="signup.php">Sign Up</a>
</div>
<?php
if(isset($message))
{
?>
<div class='taj_loginmessage'>
<p>
<?php
switch ($message)
{
case 1: echo 'Please login to continue !!';
break;
case 2: echo 'Invalid UserID or Password !!';
break;
case 3: echo 'Successfully Logged Out !!';
break;
case 4: echo 'Successfully Registered !!';
break;
case 5: echo 'Session already active @'.$resultarray["last_ip"].' time = '.$resultarray["last_login"].' Contact Admin if account compromised';
break;
}
unset($message);
?>
</p>
</div>
<?php
}
?>
</body>
</html>