forked from aakash03/Audiochat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
addFriend.php
62 lines (51 loc) · 2.01 KB
/
addFriend.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
<?php
include("php/db.php");
include("php/logged.php");
$userid = $_SESSION['id'];
if( isset( $_POST['mobile'] ) ) {
$mob = $_POST['mobile'];
$res = mysqli_query($conn,"SELECT * FROM user WHERE mobile = '$mob'");
if( mysqli_num_rows($res) == 0 ) {
die("Sorry! The provided mobile number has not yet registered :(");
}
$row = mysqli_fetch_assoc($res);
$broid = $row['id'];
$res = mysqli_query($conn,"SELECT * FROM friends WHERE bro_id = $userid AND user_id = $broid");
if( mysqli_num_rows($res) > 0 )
die("Haha :) You already have a friend request from that user!");
$res = mysqli_query($conn,"SELECT * FROM friends WHERE user_id = $userid AND bro_id = $broid");
if( mysqli_num_rows($res) > 0 )
die("Whoops! You already have sent a request to that user!");
$res = mysqli_query($conn,"INSERT INTO friends(user_id,bro_id) VALUES( $userid, $broid )");
if( $res )
{
$postdata = "name=Audiochat&no=".$mob."&msg=You have a new friend request from ".$_SESSION['name'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'http://faltusms.tk/sendSms.php');
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec($ch);
die("");
}
else
die("Some error occured! :(");
}
if( isset( $_POST['accept'] ) ) {
$broid = $_POST['id'];
if( $_POST['accept'] == 1 ) {
$res = mysqli_query($conn,"UPDATE friends SET status = 1 WHERE user_id = $broid AND bro_id = $userid");
die("OK");
}
else {
$res = mysqli_query($conn,"DELETE from friends WHERE user_id = $broid AND bro_id = $userid");
die("OK");
}
die("Error occured!");
}
?>