-
Notifications
You must be signed in to change notification settings - Fork 2
/
validate.php
101 lines (68 loc) · 2.55 KB
/
validate.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
<?php
session_start(); //starts the session
if($_SESSION['user']){ //checks if user is logged in
}
else{
header("location:keystroke_demo.php"); // redirects if user is not logged in
}
$user = $_SESSION['user']; //assigns user value
mysql_connect("localhost", "root","") or die(mysql_error()); //Connect to server
mysql_select_db("keystroke") or die("Cannot connect to database"); //Connect to database
$query = mysql_query("SELECT * from users WHERE username='$user'"); //Query the users table if there are matching rows equal to $username
while($row = mysql_fetch_assoc($query)) //display all rows from query
{
$table_password = $row['password']; // the first password row is passed on to $table_users, and so on until the query is finished
$done=$row['done'];
}
$id1=$_POST['id1'];
$id2=$_POST['id2'];
$id3=$_POST['id3'];
$id4=$_POST['id4'];
$id5=$_POST['id5'];
$id6=$_POST['id6'];
$time_data = array();
if($id1==$id2&&$id3==$id4&&$id5==$id6&&$id1==$id3&&$id1==$id5&&$id1!=""&&$table_password==$id1)
{
$myfile = fopen("data.txt","r");
$str=fread($myfile,filesize("data.txt"));
$c=0;
for ($i=0; $i <strlen($str) ; $i++) {
if($str[$i]==',')
$c=$c+1;
}
if($c==strlen($table_password)*6)
{
$str=$user.",".strlen($table_password).",".$str;
$arr=explode(".",$str); // since we later explode using comma as delimiter I need to convert str to an array, that's all
//print_r ($arr);
$file = fopen("timing.csv","a");
foreach ($arr as $line)
{
fputcsv($file,explode(',',$line)); // each array becomes a row in excel
}
fclose($file);
fclose($myfile);
$myfile = fopen("data.txt","w"); // to empty that file
fclose($myfile);
Print '<script>
alert("you are successfully entered the logistics");
window.location.assign("profile.php");</script>'; // redirects to register.php
$done_update = mysql_query("update users set done=1 WHERE username='$user'"); //Query the users table if there are matching rows equal to $username
}
else{
$myfile = fopen("data.txt", "w") or die("Unable to open file!");
fclose($myfile);
Print '<script>
alert("you could not register man! sorry!");
window.location.assign("create_account.php");</script>'; // redirects to register.php
}
}
else{
// erase the contents of the file!
$myfile = fopen("data.txt", "w") or die("Unable to open file!");
fclose($myfile);
Print '<script>
alert("you could not register man! sorry!");
window.location.assign("create_account.php");</script>'; // redirects to register.php
}
?>