Skip to content
This repository has been archived by the owner on Aug 28, 2022. It is now read-only.

Commit

Permalink
added CURLOPT_FOLLOWLOCATION = true
Browse files Browse the repository at this point in the history
For next time SD redirects the API url
  • Loading branch information
avandeputte authored Jul 30, 2017
1 parent 10821ce commit c959bc5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/includes/dvrui_common.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php

function file_get_contents_utf8($fn) {
$content = file_get_contents($fn);
return mb_convert_encoding($content, 'UTF-8');
}
function getJsonFromUrl($url) {
$content = getURL($url);
return json_decode($content, true);
Expand All @@ -21,7 +26,7 @@ function getCachedJsonFromUrl($url,$maxAgeSeconds) {
$current_time = time();
$file_time = filemtime($cachefilename);
if ($current_time - $maxAgeSeconds < $file_time){
$content = file_get_contents($cachefilename);
$content = file_get_contents_utf8($cachefilename);
}else{
unlink($cachefilename);
$content = getURL($url);
Expand All @@ -40,6 +45,7 @@ function getURL($url){
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$content = curl_exec($ch);
curl_close($ch);
} else {
Expand Down

0 comments on commit c959bc5

Please sign in to comment.