Repository navigation
Expand file tree
/
Copy pathHttpTools.php
More file actions
71 lines (56 loc) · 1.52 KB
/
Copy pathHttpTools.php
File metadata and controls
71 lines (56 loc) · 1.52 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
header('content-type:text/html;charset=utf-8');
/**
* 与http协议相关的工具类
* Class HttpTools
*/
class HttpTools{
/**
* @desc 获取当前页面的URL
* @return string
*/
function getCurrentPageURL(){
$pageURL = 'http';
if (!empty($_SERVER['HTTPS'])) {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
/**
* @desc 获取当前页域名的URL
* @return string
*/
function getDomainName(){
$pageURL = 'http';
if (!empty($_SERVER['HTTPS'])) {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":";
} else {
$pageURL .= $_SERVER["SERVER_NAME"];
}
return $pageURL;
}
/**
* @desc 解析url并得到url中的参数
* @param string $url
* @return array
*/
function convert_url_query($url = '')
{
$arr = parse_url($url);
$query_arr = explode('&', $arr['query']);
$params = array();
if($query_arr){
foreach ($query_arr as $param) {
$item = explode('=', $param);
$params[$item[0]] = $item[1];
}
}
return $params;
}
}