-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·101 lines (77 loc) · 2.87 KB
/
index.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/*
This file is free software: you can redistribute it and/or modify
the code under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
However, the license header, copyright and author credits
must not be modified in any form and always be displayed.
This class is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
@author geoPlugin ([email protected])
@copyright Copyright geoPlugin ([email protected])
This file is an example PHP file of the geoplugin class
to geolocate IP addresses using the free PHP Webservices of
http://www.geoplugin.com/
*/
require_once('geoplugin.class.php');
$geoplugin = new geoPlugin();
/*
Notes:
The default base currency is USD (see http://www.geoplugin.com/webservices:currency ).
You can change this before the call to geoPlugin::locate with eg:
$geoplugin->currency = 'EUR';
The default IP to lookup is $_SERVER['REMOTE_ADDR']
You can lookup a specific IP address, by entering the IP in the call to geoPlugin::locate
eg
$geoplugin->locate('209.85.171.100');
The default language is English 'en'
supported languages:
de (German)
en (English - default)
es (Spanish)
fr (French)
ja (Japanese)
pt-BR (Portugese, Brazil)
ru (Russian)
zh-CN (Chinese, Zn)
To change the language to e.g. Japanese, use:
$geoplugin->lang = 'ja';
*/
//locate the IP
$geoplugin->locate();
/*
echo "Geolocation results for {$geoplugin->ip}: <br />\n".
"City: {$geoplugin->city} <br />\n".
"Region: {$geoplugin->region} <br />\n".
"Region Code: {$geoplugin->regionCode} <br />\n".
"Region Name: {$geoplugin->regionName} <br />\n".
"Country Name: {$geoplugin->countryName} <br />\n".
"Country Code: {$geoplugin->countryCode} <br />\n".
"Latitude: {$geoplugin->latitude} <br />\n".
"Longitude: {$geoplugin->longitude} <br />\n";
*/
header("Location: https://api.github.com/repos/copasi/COPASI/releases/latest");
$fh = fopen("version-check.log", 'a');
if ($fh === false) return;
//Waiting until file will be locked for writing
$canWrite = false;
while (!$canWrite) {
$canWrite = flock($fh, LOCK_EX);
// If lock not obtained sleep for 2 - 5 micro seconds, to avoid colision
if(!$canWrite) {
$nanoSeconds = rand(2000, 5000); // 0 1 u = 100 miliseconds
time_nanosleep(0 , $nanoSeconds);
}
}
$iso_date = gmdate("Y-m-d\TH:i:s\Z");
// Only record if a version is provided:
if (isset($_REQUEST["version"]))
{
$version=$_REQUEST["version"];
fwrite($fh, "$iso_date,$version,$geoplugin->ip,$geoplugin->city,$geoplugin->region,$geoplugin->regionCode,$geoplugin->regionName,$geoplugin->countryName,$geoplugin->countryCode,$geoplugin->latitude,$geoplugin->longitude\n");
}
fclose($fh);
?>