Buongiorno a tutti,
possiedo un sito sul vostro fantastico servizio di Hosting Gratuito:
http://pernixpugnax.altervista.org/
E' un sito di un clan per Battlefield BadCompany 2 gioco per Playstation3, ho scoperto che esiste un sito che rilascia un API per sapere in tempo reale e sul PROPRIO sito tramite un codice PHP tutte le statistiche relative al gioco; mi sono scervellato per un po' dato che il codice suggerito dal sito non funzionava e non essendo un GURU di PHP non riesco a venirne a capo.
Ho pero' scoperto che il problema dipende da ALTERVISTA dato che su un dominio di un'azienda per cui ho fatto un sito funziona tutto correttamente;
ma andiamo con ordine:
- il codice in questione è questo:
Codice PHP:
<?php
$url = 'http://api.bfbcs.com/api/pc'; // This is the URL to the API
$postdata = 'players=LordDusk,Hogader&fields=all'; // Here you add your names and change the "fields" value (please look at the site for the value explanation)
// This bunch of code is fetching the data
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
$data = curl_exec($ch);
curl_close($ch);
// Here we are decoding the JSON to PHP (Array(s))
$data = json_decode($data,true);
// To make it look tidy, we put all the data into one variable
foreach($data['players'] as $pd)
{
// A little example
if ($pd['rank'] < 10) {
echo "Rank: <img src=\"http://battlefieldbadcompany2.com/files/gui/img/stats/ranks/tiny/R00" . $pd['rank'] . ".png\"></b><br />";
} else {
echo "Rank: <img src=\"http://battlefieldbadcompany2.com/files/gui/img/stats/ranks/tiny/R0" . $pd['rank'] . ".png\"></b><br />";
}
echo "Name: <b>".$pd['name']."</b><br/>";
echo "Kills: <b>".$pd['kills']."</b><br />";
echo "Kills per Minute: <b>".number_format($pd['kills']/($pd['time']/60), 2, '.', '')."</b><br />";
echo "Deaths: <b>".$pd['deaths']."</b><br />"; // Displays the players score
echo "Deaths per Minute: <b>".number_format($pd['deaths']/($pd['time']/60), 2, '.', '')."</b><br />";
echo "K/D Ratio: <b>".round($pd['kills']/$pd['deaths'], 2)."</b><br />";
echo "Time: <b>".sec2hms($pd['time'])."</b><br />";
echo "Dogtags: <b>".$pd['general']['dogt']."</b><br />";
echo "Dogtags per Minute: <b>".number_format($pd['general']['dogt']/($pd['time']/60), 2, '.', '')."</b><br /><br />"; // Displays the players score
}
echo base64_decode('PGEgaHJlZj0iaHR0cDovL2JmYmNzLmNvbSIgdGFyZ2V0PSJfYmxhbmsiPlBvd2VyZWQgYnkgYmZiY3MuY29tPC9hPg==');
function sec2hms ($sec, $padHours = false)
{
$hms = "";
$hours = intval(intval($sec) / 3600);
$hms .= ($padHours)
? str_pad($hours, 2, "0", STR_PAD_LEFT). ':'
: $hours. 'h ';
$minutes = intval(($sec / 60) % 60);
$hms .= str_pad($minutes, 2, "0", STR_PAD_LEFT). 'm ';
$seconds = intval($sec % 60);
$hms .= str_pad($seconds, 2, "0", STR_PAD_LEFT).'s';
return $hms;
}
?>
Il risultato CORRETTO di questo codice lo potete trovare qui:
REMOVE (server aruba)
Se riporto lo stesso file php sul server di Altervista il risultato è una pagina completamente bianca:
http://pernixpugnax.altervista.org/test_API/test-2.php
Le impostazioni per htaccess di altervista sono queste (versione avanzata):
Codice PHP:
##
# @version $Id: htaccess.txt 10492 2008-07-02 06:38:28Z ircmaxell $
# @package Joomla
# @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
# @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
# Joomla! is Free Software
##
#####################################################
# READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE
#
# The line just below this section: 'Options +FollowSymLinks' may cause problems
# with some server configurations. It is required for use of mod_rewrite, but may already
# be set by your server administrator in a way that dissallows changing it in
# your .htaccess file. If using it causes your server to error out, comment it out (add # to
# beginning of line), reload your site in your browser and test your sef url's. If they work,
# it has been set by your server administrator and you do not need it set here.
#
#####################################################
## Can be commented out if causes errors, see notes above.
Options +FollowSymLinks
#
# mod_rewrite in use
RewriteEngine On
########## Begin - Rewrite rules to block out some common exploits
## If you experience problems on your site block out the operations listed below
## This attempts to block the most common type of exploit `attempts` to Joomla!
#
# Block out any script trying to set a mosConfig value through the URL
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Send all blocked request to homepage with 403 Forbidden error!
RewriteRule ^(.*)$ index.php [F,L]
#
########## End - Rewrite rules to block out some common exploits
# Uncomment following line if your webserver's URL
# is not directly related to physical file paths.
# Update Your Joomla! Directory (just / for root)
# RewriteBase /
########## Begin - Joomla! core SEF Section
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ [NC]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
#
########## End - Joomla! core SEF Section
# # av:php5-engine
AddHandler av-php5 .php
# # av:PHP-RG
php_flag register_globals on
Versione semplice:
Register Globals ON
Upload di file con PHP DEFAULT
Attiva supporto php5 (off = php4) ON
Spero vivamente che mi aiutate a capire come visualizzare il tutto anche sul mio sito di altervista.
GRAZIE!!!