-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
50 lines (42 loc) · 1.49 KB
/
functions.php
File metadata and controls
50 lines (42 loc) · 1.49 KB
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
<?php
function getArea($user_profile){
$ip = !empty($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
$url = "http://freegeoip.net/json/".$ip;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
$data = curl_exec($ch);
curl_close($ch);
if ($data) {
$location = json_decode($data);
$lat = $location->latitude;
$lon = $location->longitude;
if($user_profile=="none" && isset($userid)){
$sql = "UPDATE users SET lat=".$lat." AND long=".$lon." WHERE id=".userid;
mysql_query($sql);
}else{
$sql = "UPDATE users SET lat=".$lat." AND long=".$lon." WHERE fb_id=".$user_profile["id"];
mysql_query($sql);
}
// mysql_query("INSERT INTO users (lat, long) VALUES ('".$lat."','".$lon."')");
return array('latitude'=>$lat,'longitude'=>$lon);
}
}
function getAllLoggedUser(){
$result = mysql_query("SELECT * FROM users where is_online='y'");
return $result;
}
function saveProfile($user_profile){
if($user_profile=="none"){
mysql_query("INSERT INTO users (name,is_online) VALUES ('guest','y')");
$id=mysql_insert_id();
define('userid', $id);
}else{
$result = mysql_query("SELECT fb_id FROM users where fb_id='".$user_profile['id']."'");
if(!$result){
mysql_query("INSERT INTO users (name, gender,fb_id,is_online) VALUES ('".$user_profile['first_name']."', '".$user_profile['gender']."','".$user_profile['id']."','y')");
}
}
}
?>