I'm currently creating a bootstrap website using my Fortnite stats as data and eventually posting it on my twitch feed. However, I've managed to get it to work perfectly when I run on my local machine but when I uploaded it to my hostgator directory the site loads fine it just has no data. The error I'm getting I believe refers to my JSON file but I'm assuming the only reason this error is occurring is because there is no data in there as it's not working with the Fortnite API when ran on anything other than my local machine. Has anyone else ever experienced anything like this before?
The Error:
Source map error: SyntaxError: JSON.parse: unexpected character at line 2 column 1 of the JSON data
Source Map URL: bootstrap.min.css.map
This is my code I assume there's not much point in posting it as if it runs on my local machine logic says it's fine, right?
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.fortnitetracker.com/v1/profile/psn/myusername");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'TRN-Api-Key: mykey'
));
$response = curl_exec($ch);
curl_close($ch);
$fp = fopen("stats.json", "w");
fwrite($fp, $response);
fclose($fp);
$data = json_decode(file_get_contents("stats.json"));
$solo = $data->stats->p2;//solos data
$duos = $data->stats->p10;//duos data
$squads = $data->stats->p9;//squads data
$solo_wins = $solo->top1->valueInt;
$duos_wins = $duos->top1->valueInt;
$squads_wins = $squads->top1->valueInt;
$solo_matches = $solo->matches->valueInt;
$duos_matches = $duos->matches->valueInt;
$squads_matches = $squads->matches->valueInt;
$solo_kd = $solo->kd->valueDec;
$duos_kd = $duos->kd->valueDec;
$squads_kd = $squads->kd->valueDec;
$solo_games = $solo->matches->valueInt;
$duos_games = $duos->matches->valueInt;
$squads_games = $squads->matches->valueInt;
$solo_kills = $solo->kills->valueInt;
$duos_kills = $duos->kills->valueInt;
$squads_kills = $squads->kills->valueInt;
?>
You're correct that this problem has occurred to others: it seems that Hostgator does not automatically allow SSH and cURL to be combined (link). If you google "Hostgator cURL
you already get some useful responses. Several people (such as this one and a commenter here one) have reported that updating to PHP 5.5/5.6 resolves the issue. I'd certainly suggest you check the suggestions made by Stanislav in the comments of the later.
Another solution might lie in disabling CURLOPT_SSL_VERIFYPEER
and the other SSL options.
Without the actual error message returned by curl_exec
however, your current question does not supply us with enough information to pinpoint the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With