/
activate.php
60 lines (47 loc) · 1.27 KB
/
activate.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
<?php
include('header.php');
include('getInputSafe.php');
sleep(1);//avoid spam
$code = $_GET['code'];
function verifyCode() {
global $code;
$db = new PDO('sqlite:database.db');
$stmt = $db->prepare('SELECT * FROM users WHERE code=?');
$stmt->execute(array($code));
$result=$stmt->fetchAll();
if (count($result) == 0) {
return 0;
}
else {
return $result[0]['id'];
}
}
function activateUser($id) {
global $code;
$db = new PDO('sqlite:database.db');
$stmt = $db->prepare('SELECT active FROM users WHERE id=?');
$stmt->execute(array($id));
$result=$stmt->fetchAll();
if($result[0]['active']==1) {
return 1;
}
else {
$stmt = $db->prepare("UPDATE users
SET active=1
WHERE id=?");
$stmt->execute(array($id));
$result=$stmt->fetchAll();
return 0;
}
}
$id=verifyCode();
if($id==0) {
echo "<script type='text/javascript'>alert('Code is not valid. Returning to main page.');window.location.href = 'main.php';</script>";
}
else if(activateUser($id)==1){
echo "<script type='text/javascript'>alert('User already activated. You can log in.');window.location.href = 'main.php';</script>";
}
else {
echo "<script type='text/javascript'>alert('User succesfully activated. You can log in.');window.location.href = 'main.php';</script>";
}
?>