-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.php
320 lines (277 loc) · 13.8 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
<meta charset="utf-8">
<title>API USAGE</title>
<link rel="shortcut icon" href="https://github.com/Kratos237/Geo-Localisation-Ip-API/raw/master/ipIcon.png" type="image/x-icon">
<script src='https://api.mapbox.com/mapbox-gl-js/v1.7.0/mapbox-gl.js'></script>
<link href='https://api.mapbox.com/mapbox-gl-js/v1.7.0/mapbox-gl.css' rel='stylesheet' />
<center style="color:gray;margin-top:20px;">
<center style="color:gray;margin-top:20px;">
<?php
// Daniel Uokof
//Adresse de l'api https://extreme-ip-lookup.com/
//04 fevrier 2020, Yaounde
date_default_timezone_set("africa/douala");
function get_ip()
{
//-- Fonction de récupération de l'adresse IP du visiteur
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
isset($_GET['ip']) ? $ip = $_GET['ip'] : $ip;
//Testeur d'adresse ip.
$tabIp = explode(".", $ip);
for ($i = 0; $i < 4; $i++) {
isset($tabIp[$i]) ? $ipTrue = true : $ipTrue = false;
}
//Generateur d'adresse ip si la votre est incorrecte, si vous testez en local par exemple.
$ipDefault = mt_rand(0, 192) . "." . mt_rand(0, 240) . "." . mt_rand(0, 100) . "." . mt_rand(0, 240);
if ($ipTrue == false) {
return array("ip" => $ipDefault, "state" => $ipTrue);
} else {
if ($ip != "127.0.0.1") {
return array("ip" => $ip, "state" => $ipTrue);
} else {
return array("ip" => $ipDefault, "state" => $ipTrue);
}
}
}
function iso3($pays)
{
$iso = @json_decode(file_get_contents("https://restcountries.eu/rest/v2/alpha/$pays"), true);
return array($iso['alpha3Code'], $iso['translations']['fr']);
}
function infocovid($pays)
{
//$pays=iso3($pays);
$covid = json_decode(file_get_contents("https://covid-19.dataflowkit.com/v1/$pays"), true);
return array(true, $covid, $pays);
}
function apiGeoLocalisation()
{
$ipResponse = get_ip();
$message = "Votre addresse ip n'est pas valide mais mon petit generateur d'ip a cree une adresse pour vous, la voici: " . $ipResponse['ip'];
$geo = @json_decode(file_get_contents("http://extreme-ip-lookup.com/json/" . $ipResponse['ip']/*?callback=getIP*/));
if (isset($geo->status)) {
if ($geo->city) {
if ($geo->status == "success") {
$pays = $geo->country;
$ville = $geo->city;
$ipType = $geo->ipType;
$codePays = $geo->countryCode;
if ($ipResponse["state"] == false) {
echo "<br>" . $message . "<br><br>";
}
echo "
<div id='map' style='width: 400px; height: 300px;'></div>
<div id='menu'>
<h4>Style de carte.</h4><br><br>
<input
id='streets-v11'
type='radio'
name='rtoggle'
value='streets'
checked='checked'
/>
<label for='streets'>Rues</label>
<input id='light-v10' type='radio' name='rtoggle' value='light' />
<label for='light'>Claire</label>
<input id='dark-v10' type='radio' name='rtoggle' value='dark' />
<label for='dark'>Sombre</label>
<input id='outdoors-v11' type='radio' name='rtoggle' value='outdoors' />
<label for='outdoors'>Simple</label>
<input id='satellite-v9' type='radio' name='rtoggle' value='satellite' />
<label for='satellite'>satellite</label>
</div>
<br><br>
";
echo "Le visiteur ayant l'adresse ip " . $ipResponse['ip'] . " est dans le pays: <span style='color:teal'>$pays ($codePays)</span>, dans la ville de <span style='color:lightcoral'>$ville.</span>, inutile de preciser que ce pays est dans le continent <span style='color:rgb(110, 6, 55)'>$geo->continent.</span>\n";
echo " <br><br>
Ses coordonnes geographiques sont: <br>
<ul>
<li>Longitude:<span style='color:orange'> $geo->lon</span></li>
<li>Latitude:<span style='color:orange'> $geo->lat</span></li>
</ul>
<br>";
echo "
<style>
#menu {
position: relative;
background: #fff;
padding: 10px;
font-family: 'Open Sans', sans-serif;
}
</style>
<script>
mapboxgl.accessToken = 'pk.eyJ1Ijoid29vdGFya292c2tpIiwiYSI6ImNrNmMzYTN2MDB4NTEza21ncjIwdHIxczEifQ.vIsFKXlEkPMKclA4KZQhLw';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v11',
zoom: 14,
center: [4.899, 52.372]
});
var layerList = document.getElementById('menu');
var inputs = layerList.getElementsByTagName('input');
function switchLayer(layer) {
var layerId = layer.target.id;
map.setStyle('mapbox://styles/mapbox/' + layerId);
}
for (var i = 0; i < inputs.length; i++) {
inputs[i].onclick = switchLayer;
}
</script>
<script>
mapboxgl.accessToken = 'pk.eyJ1Ijoid29vdGFya292c2tpIiwiYSI6ImNrNmMzYTN2MDB4NTEza21ncjIwdHIxczEifQ.vIsFKXlEkPMKclA4KZQhLw';
var map = new mapboxgl.Map({
container: 'map',
zoom: 16,
style: 'mapbox://styles/mapbox/streets-v11',
center: [" . $geo->lon . "," . $geo->lat . ", -0.47],
});
var size = 200;
var pulsingDot = {
width: size,
height: size,
data: new Uint8Array(size * size * 4),
// get rendering context for the map canvas when layer is added to the map
onAdd: function() {
var canvas = document.createElement('canvas');
canvas.width = this.width;
canvas.height = this.height;
this.context = canvas.getContext('2d');
},
// called once before every frame where the icon will be used
render: function() {
var duration = 1000;
var t = (performance.now() % duration) / duration;
var radius = (size / 2) * 0.3;
var outerRadius = (size / 2) * 0.7 * t + radius;
var context = this.context;
// draw outer circle
context.clearRect(0, 0, this.width, this.height);
context.beginPath();
context.arc(
this.width / 2,
this.height / 2,
outerRadius,
0,
Math.PI * 2
);
context.fillStyle = 'rgba(255, 200, 200,' + (1 - t) + ')';
context.fill();
// draw inner circle
context.beginPath();
context.arc(
this.width / 2,
this.height / 2,
radius,
0,
Math.PI * 2
);
context.fillStyle = 'rgba(255, 100, 100, 1)';
context.strokeStyle = 'white';
context.lineWidth = 2 + 4 * (1 - t);
context.fill();
context.stroke();
// update this image's data with data from the canvas
this.data = context.getImageData(
0,
0,
this.width,
this.height
).data;
// continuously repaint the map, resulting in the smooth animation of the dot
map.triggerRepaint();
// return `true` to let the map know that the image was updated
return true;
}
};
map.on('load', function() {
map.addImage('pulsing-dot', pulsingDot, { pixelRatio: 2 });
map.addSource('points', {
'type': 'geojson',
'data': {
'type': 'FeatureCollection',
'features': [
{
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [" . $geo->lon . ", " . $geo->lat . "],
}
}
]
}
});
map.addLayer({
'id': 'points',
'type': 'symbol',
'source': 'points',
'layout': {
'icon-image': 'pulsing-dot'
}
});
});
</script>";
echo "
Pour un plus, son fournisseur d'acces internet est <span style='color:rgb(0, 121, 26)'>$geo->isp.</span>
<br>
<!-- bouton rechercher une adresse ip -->
<h4 style='position:fixed;top:20px; left:20'>Rechercher une adresse ip: <form method='get'><input type='text' name='ip'><br><br><input type='submit' style='background:darkorange; color:white;border:1px solid black; box-shadow: 0px 0px 2px gray; padding:5px 10px;' value='Valider'></form></h4>";
} else {
echo "Un probleme est survenu avec l'API.";
}
//
$info = infocovid(rawurlencode($pays == "United States" ? "USA" : $pays))[1];
echo "
<br/>
<div style='border:1px solid red; padding:10px 20px'>
Le pays <span style='color:green'>" . $info['Country_text'] . "</span>
compte (a la date du " . $info['Last Update'] . ")
<span style='color:orange'>" . $info['Total Cases_text'] . "</span> cas confirmes de COVID 19 avec
<span style='color:green'>" . $info['Total Recovered_text'] . "</span> gueris;
<span style='color:red'>" . $info['Total Deaths_text'] . " deces;</span>
" . $info['Active Cases_text'] . " cas actifs.
</div>
";
echo "<h4>Si vous voulez consulter de vous meme la reponse originale de l'api cliquez <a style='color:lightblue' href='http://extreme-ip-lookup.com/json/" . $ipResponse['ip'] . "' target='_blank'>sur moi.</a></h4>";
} else {
echo "<div class='notification'>Les informations renvoyees par le service sont vides donc inutilie de les renvoyer.</div>";
}
} else {
echo "<div class='notification'>Cette API n'est pas fonctionnelle ou vous avez peut-etre une mauvaise connexion internet.</div>";
}
}
//Appel de la fonction
apiGeoLocalisation();
?>
<!-- Place this tag where you want the button to render. -->
<br><br><br><br><br><br><br>
<style>
div.mapboxgl-ctrl{
display:none!important;
opacity:0!important;
color:transparent!important;
width:0px!important;
}
</style>
<style>#forkongithub a{background:black;color:darkorange;text-decoration:none;font-family:arial,sans-serif;text-align:center;font-weight:bold;padding:5px 40px;font-size:1rem;line-height:2rem;position:relative;transition:0.5s;}#forkongithub a:hover{background:black;color:teal;}#forkongithub a::before,#forkongithub a::after{content:"";width:100%;display:block;position:absolute;top:1px;left:0;height:1px;background:purple;}#forkongithub a::after{bottom:1px;top:auto;}@media screen and (min-width:800px){#forkongithub{position:absolute;display:block;top:0;right:0;width:200px;overflow:hidden;height:200px;z-index:9999;}#forkongithub a{width:200px;position:absolute;top:60px;right:-60px;transform:rotate(45deg);-webkit-transform:rotate(45deg);-ms-transform:rotate(45deg);-moz-transform:rotate(45deg);-o-transform:rotate(45deg);box-shadow:4px 4px 10px rgba(0,0,0,0.8);}}</style><span id="forkongithub"><a href="https://github.com/Kratos237/Geo-Localisation-Ip-API">Fork me on GitHub</a></span>
<style>
.notification{
position:absolute;
top:50%;
left:50%;
transform:translateX(-50%);
font-size: 14px;
color: orange;
}
body, #menu{
background-color:black;
}
</style>
<footer style="position:fixed; bottom:0; height:50px; width:105%; color:white;left:-5px; background:black;">
<span style="position:relative; top:20px">Fait avec amour par <a href="http://github.com/heronational" target="_blank" style="color:darkorange">Daniel Uokof</a></span>
</footer>
</center>