-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgetFriends.php
More file actions
44 lines (40 loc) · 898 Bytes
/
getFriends.php
File metadata and controls
44 lines (40 loc) · 898 Bytes
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
<?php
require 'database.php';
header("Content-Type: application/json");
ini_set("session.cookie_httponly", 1);
session_start();
date_default_timezone_set('America/Chicago');
$my_id=$_SESSION['user_id'];
$stmt=$mysqli->prepare("SELECT user_id FROM shares WHERE friend_id=?");
if(!$stmt){
echo json_encode(array(
"success" => false
));
printf("Query Prep Failed: %s\n", $mysqli->error);
exit;
}
$stmt->bind_param('i', $my_id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$list = array();
while($row = $result->fetch_assoc()){
array_push($list, array(
"id" => $row['user_id']
));
}
echo json_encode(array(
"success" => true,
"exists" => true,
"friends" => $list
));
exit;
}else{
echo json_encode(array(
"success" => false,
"message" => "No friends"
));
exit;
}
$stmt->close();
?>