Skip to content

Commit 851e832

Browse files
author
Michael Ciarlo
committed
updating proxy
1 parent a71ea6d commit 851e832

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

js/utils/proxy.php

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,43 @@
1+
<?php
12

2-
Notice: Undefined index: url in /srv/www/jsonlint/proxy.php on line 3
3-
{ "result": "Invalid URL. Please check your URL and try again.", "error": true }{ "result": "Unable to parse URL. Please check your URL and try again.", "error": true }
3+
$url = filter_var($_POST['url'], FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED);
4+
5+
if (!$url || !preg_match("/^https?:/i", $url)) {
6+
echo '{ "result": "Invalid URL. Please check your URL and try again.", "error": true }';
7+
}
8+
9+
$ch = curl_init($url);
10+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
11+
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
12+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
13+
$data = curl_exec($ch);
14+
$info = curl_getinfo($ch);
15+
curl_close($ch);
16+
17+
if ($data === false) {
18+
echo '{ "result": "Unable to parse URL. Please check your URL and try again.", "error": true }';
19+
return;
20+
}
21+
22+
$contentLength = intval($info['download_content_length']);
23+
$status = intval($info['http_code']);
24+
25+
if ($status >= 400) {
26+
echo '{ "result": "URL returned bad status code ' . $status . '.", "error": true }';
27+
return;
28+
}
29+
30+
if ($contentLength >= 52428800) {
31+
echo '{ "result": "URL content length greater than 10 megs (' . $contentLength . '). Validation not available for files this large.", "responseCode": "1" }';
32+
return;
33+
}
34+
35+
$response = new StdClass();
36+
$response->status = $status;
37+
$response->length = $contentLength;
38+
$response->url = $info['url'];
39+
$response->content = $data;
40+
41+
echo json_encode($response);
42+
43+
?>

0 commit comments

Comments
 (0)