-
Notifications
You must be signed in to change notification settings - Fork 2
/
delete_user_confirm.php
81 lines (70 loc) · 3.18 KB
/
delete_user_confirm.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
<?php
/**
* Wipe all user data from the database and redirect back to the login page.
*
* @version PHP 8.0.12
* @since May 2022
* @author AtharvaShah
*/
/*------------------------------------------------------------------------------------------------
DESCRIPTION: CHECKS IF A USER HAS LOGGED IN AND IF SO, DELETES THE USER DATA FROM THE DATABASE.
------------------------------------------------------------------------------------------------*/
require "connection.php";
require "functions.php";
// if GET REQUEST IS MADE FROM ADMIN PAGE SET USERNAME TO IT
if (isset($_GET['user_name'])) {
$username = $_GET['user_name'];
}
// else assume user is logged in and delete their own data from the database
else {
session_start();
if (empty($_SESSION)) {
header("Location: login.php");
}
$user_data = check_login($con);
$username = $user_data['user_name']; //username of the currently logged in user
}
if (isset($_SESSION['user_id'])) {
set_inactive($username);
unset($_SESSION['user_id']);
}
/* ------------------------------------------------------------------------------------------------
DELETES THE USERS FROM THE USERS TABLE IN THE DATABASE.
------------------------------------------------------------------------------------------------*/
$sql = "DELETE FROM `users` WHERE `user_name` = '$username'";
if ($result = mysqli_query($con, $sql)) {
echo "Deleted the User";
} else {
die('Unable to delete the account in Users Table' . mysqli_error($con));
}
/*------------------------------------------------------------------------------------------------
DELETES THE ASSOCIATED RECORDS OF THE USER FROM THE DATA TABLE
------------------------------------------------------------------------------------------------*/
$sql2 = "DELETE FROM `data` WHERE `username` = '$username'";
if ($result = mysqli_query($con, $sql2)) {
echo "Deleted the Data associated with the user.";
} else {
die('Unable to delete User Data in Data Table' . mysqli_error($con));
}
/*------------------------------------------------------------------------------------------------
DELETES ALL THE RECORDS WHERE USER WAS FOLLOWING OTHER PEOPLE
------------------------------------------------------------------------------------------------*/
$sql3 = "DELETE FROM `social` WHERE `follower_username` = '$username'";
if ($result = mysqli_query($con, $sql3)) {
echo "Removed all the records where user was following other people.";
} else {
die('Unable to delete User Data in Social "SQL3"' . mysqli_error($con));
}
/*------------------------------------------------------------------------------------------------
DELETES SELECTIVE RECORDS WHERE OTHER PEOPLE FOLLOWED THE USER. ------------------------------------------------------------------------------------------------*/
$sql4 = "DELETE FROM `social` WHERE `followed_username` = '$username'";
if ($result = mysqli_query($con, $sql4)) {
echo "Removed all the records where other people were following the user.";
echo "ACCOUNT IS DELETED. REDIRECTING TO SIGNUP PAGE.";
session_destroy();
header("Location: login.php");
die;
} else {
die('Unable to delete User Data in Social "SQL4"' . mysqli_error($con));
}
?>