-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunction.php
More file actions
165 lines (137 loc) · 4.13 KB
/
function.php
File metadata and controls
165 lines (137 loc) · 4.13 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
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
<?php
/*
<JasperRSSReader> Copyright (C) 2018 Jaspers
File: function.php
Author: Jaspers
Created by 2018-07-14
Description:
*/
header("Content-Type: text/html; charset=UTF-8");
header('X-Frame-Options: DENY'); // 'X-Frame-Options'
class RSSFunction{
// 수행시간 측정
public function getExecutionTime() {
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
public function getCopyright(){
echo "\t\t\t<div id=\"ft_information\">\n";
echo "\t\t\t\t<p>Copyright © Jasper(rabbit.white at daum dot net)</p>\n";
echo "\t\t\t\t<p>E-mail : rabbit.white at daum dot net</p>\n";
echo "\t\t\t\t<p>Powered By ";
echo "<span style=\"font-weight:bold;\">dothome.co.kr</span><br></p>\n";
echo "</div>";
}
public function get_url_fsockopen($url)
{
// http://
if ( strpos($url, "https://", 0) == -1 ){
$URL_parsed = parse_url($url);
$host = $URL_parsed["host"];
$port = $URL_parsed["port"];
if ($port==0)
$port = 80;
$path = $URL_parsed["path"];
if ($URL_parsed["query"] != "")
$path .= "?".$URL_parsed["query"];
$out = "GET $path HTTP/1.0\r\nHost: $host\r\n\r\n";
$fp = fsockopen($host, $port, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br>\n";
} else {
fputs($fp, $out);
$body = false;
while (!feof($fp)) {
$s = fgets($fp, 128);
if ( $body )
$in .= $s;
if ( $s == "\r\n" )
$body = true;
}
fclose($fp);
return $in; // string으로 받고싶을땐...
}
}
// https://
else{
$response = $this->getSSLFileContent($url);
return $response;
}
}
public function getSSLFileContent($url, $method = 'GET')
{
// Initialize
$info = parse_url($url);
$req = '';
$data = '';
$line = '';
$agent = 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0)';
$linebreak = "\r\n";
$headPassed = false;
// Setting Protocol
switch($info['scheme'] = strtoupper($info['scheme']))
{
case 'HTTP':
$info['port'] = 80;
break;
case 'HTTPS':
$info['ssl'] = 'ssl://';
$info['port'] = 443;
break;
default:
return false;
}
// Setting Path
if(!$info['path'])
{
$info['path'] = '/';
}
// Setting Request Header
switch($method = strtoupper($method))
{
case 'GET':
if($info['query'])
{
$info['path'] .= '?' . $info['query'];
}
$req .= 'GET ' . $info['path'] . ' HTTP/1.1' . $linebreak;
$req .= 'Host: ' . $info['host'] . $linebreak;
$req .= 'User-Agent: ' . $agent . $linebreak;
$req .= 'Referer: ' . $url . $linebreak;
$req .= 'Connection: Close' . $linebreak . $linebreak;
break;
case 'POST':
$req .= 'POST ' . $info['path'] . ' HTTP/1.1' . $linebreak;
$req .= 'Host: ' . $info['host'] . $linebreak;
$req .= 'User-Agent: ' . $agent . $linebreak;
$req .= 'Referer: ' . $url . $linebreak;
$req .= 'Content-Type: application/x-www-form-urlencoded'.$linebreak;
$req .= 'Content-Length: '. strlen($info['query']) . $linebreak;
$req .= 'Connection: Close' . $linebreak . $linebreak;
$req .= $info['query'];
break;
}
// Socket Open
$fsock = @fsockopen($info['ssl'] . $info['host'], $info['port']);
if ($fsock)
{
fwrite($fsock, $req);
while(!feof($fsock))
{
$line = fgets($fsock, 128);
if($line == "\r\n" && !$headPassed)
{
$headPassed = true;
continue;
}
if($headPassed)
{
$data .= $line;
}
}
fclose($fsock);
}
return $data;
}
}
?>