-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyIP.php
37 lines (34 loc) · 1.1 KB
/
myIP.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
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Workerman\Worker;
use Workerman\Connection\TcpConnection;
use Workerman\Protocols\Http\Request;
use Workerman\Protocols\Http\Response;
$context = array(
'ssl' => array(
'local_cert' => '/path_to/your.cer',
'local_pk' => '/path_to/your.key',
'verify_peer' => false,
'allow_self_signed' => false,
)
);
$myip = new Worker("http://[::]:443", $context);
$myip->transport = 'ssl';
$myip->name = 'WhatIsYourIP';
$myip->onMessage = function (TcpConnection $connection, Request $request) {
$ip = ($request->header('X-Real-IP')) ?
$request->header('X-Real-IP') : $connection->getRemoteIp();
if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
list(, $ip) = explode('ffff:', $ip);
$ip = rtrim($ip, ']');
}
$response = new Response(200, [
'X-Powered-By' => 'Workerman ' . Worker::VERSION,
'Connection' => 'close',
'Content-Type' => 'text/plain; charset=UTF-8'
], $ip);
$connection->close($response);
};
if (!defined('GLOBAL_START')) {
Worker::runAll();
}