-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfollow_user.php
36 lines (28 loc) · 1.03 KB
/
follow_user.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
<?php
// display error message
error_reporting(E_ALL);
ini_set('display_errors', true);
// include library
include 'lib/utils.php';
$is_success = 0;
// get user input
if(isset($_REQUEST['fid'])) $fid = $_REQUEST['fid'];
if(!isset($fid)) {echo $is_success; return;}
if(isset($_REQUEST['follow'])) $action = $_REQUEST['follow'];
if(!isset($action)) {echo $is_success; return;}
if(isset($_COOKIE['author_id'])) $author_id = $_COOKIE['author_id'];
if(!isset($author_id)) {echo $is_success; return;}
// connect to database
$cid = mysqli_connect($dbhost, $dbusername, $dbpassword, $dbname);
if(!$cid) {echo $is_success; return;}
// set character set
mysqli_set_charset($cid, 'utf8');
$sql = 'insert ignore into following (from_id, to_id, timestamp, is_active) values(\'' . $author_id . '\', \'' . $fid . '\', '
. 'current_timestamp(), \'' . $action . '\');';
$result = mysqli_query($cid, $sql);
if(!$result) {echo $is_success; return;}
$is_success = 1;
// close connection
mysqli_close($cid);
echo $is_success;
?>