-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.php
44 lines (32 loc) · 815 Bytes
/
util.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
<?php
function get_param( $key, $default = '' ) {
return isset( $_GET[$key] ) ? $_GET[$key] : $default;
}
function json_response( $response, $http_status = 200 ) {
// CORS header
header( 'Access-Control-Allow-Origin: *' );
// No-cache header.
header( 'Cache-Control: no-cache' );
http_response_code( $http_status );
header( 'Content-type: application/json' );
echo json_encode( $response );
}
function parse_domain( $query ) {
$query = trim( $query );
if ( $query == '' ) {
return false;
}
if ( 0 === strrpos( $query, 'http' ) ) {
$url = parse_url( $query );
$domain = $url['host'];
} else {
$domain = $query;
}
$match_domain = "/([-\w]+\.\w+)$/";
if ( preg_match( $match_domain, $domain, $matches) ) {
$domain = $matches[1];
} else {
$domain = false;
}
return $domain;
}