Alors j'ai réusi en me basant sur plusieurs scripts.
Mais il y à toujours une erreur.
J'explique la première partie du script doit récupérer des donées sur un serveur shoutcast puis les mettres dans une variable
$song = le nom de la chanson
Puis quand la chanson est prise il crée un fichier txt avec le nom de la chanson. Exemple :
Chanson 1 - Artiste Bien.txt
Chanson 1 - Artiste Mal.txt
Mais il ne le fais pas il fais ceci :
.txt (il ne met pas de nom)
Pouvez-vous corriger mon script svp ?
<?php
// simple.php - shoutcast 7.html information display utility
// version 0.1.5
// To use this script, save this page save simple.php then edit the information below as noted, uncomment what you need
// To imbed the information on your php site use the include function on the page you wish to display the information
// Edit the next two lines with your server information
$host = "masterofquebec.ath.cx";
$port = "8000";
// Connect to server
$fp=@fsockopen($host,$port,&$errno,&$errstr,10);
if (!$fp) {
echo "Erreur";
} else {
// Get data from server
fputs($fp,"GET /7 HTTP/1.1\nUser-Agent:Mozilla\n\n");
// exit if connection broken
for($i=0; $i<1; $i++) {
if(feof($fp)) break;
$fp_data=fread($fp,31337);
usleep(500000);
}
// Strip useless junk from source data
$fp_data=ereg_replace("^.*<body>","",$fp_data);
$fp_data=ereg_replace("</body>.*","",$fp_data);
// Place values from source into variable names
list($current,$status,$peak,$max,$reported,$bit,$song) = explode(",", $fp_data, 7);
$trackpattern = "/^[0-9][0-9] /";
$trackreplace = "";
$song = preg_replace($trackpattern, $trackreplace, $song);
if ($status == "1") {
// To use any of the outputs below just uncomment (remove the double forward slashes) that line.
// Below is an example of all data available in the 7.html file made by the Shoutcast server
// **ON BY DEFAULT - COMMENT OUT (put to forwards slashes in front of it) TO HIDE
// echo "<html>\n<head>\n<title></title>\n</head>\n<body>\nCurrent Listeners: $current<br>\nServer Status: $status<br>\nListener Peak: $peak<br>\nMaximum Listener: $max<br>\nReported Listeners: $reported<br>\nBroadcast Bitrate: $bit<br>\nCurrent Song: $song\n</body>\n</html>";
// Below is a basic one line value of the current song, perfect for front pages of sites
} else {
} }
// the questions and the answers
$pool_question="Do you like copy and paste scripts?";
$pool_option[1]="Yes";
$pool_option[2]="No";
// If counter files are not available,they will be created
// You may remove next lines after the first use of the script
if (!file_exists("$songg.txt")){
// next two lines will not work if writing permissions are not available
// you may create the files bellow manualy with "0" as their unique content
file_put_contents ("$songg.txt",0);
file_put_contents ("$songb.txt",0);
}
// retrieve data saved in files
$pool_responses[1]=file_get_contents("$songg.txt");
$pool_responses[2]=file_get_contents("$songb.txt");
// if user votes, increase corresponding value
if ($_POST["7680777"] and $_POST["7680777b"]==""){
if ($_POST["7680777"]==1) {$pool_responses[1]++;file_put_contents("$songg.txt",$pool_responses[1]);}
if ($_POST["7680777"]==2) {$pool_responses[2]++;file_put_contents("$songb.txt",$pool_responses[2]);}
}
// get percentajes for each answer in the pool
// get total number of answers
$total_responses=$pool_responses[1]+$pool_responses[2];
if ($total_responses==0){$total_responses=1;} // to avoid errors at start
// compute percentajes (with one decimal number)
$pool_percentaje[1] = round((100*$pool_responses[1])/$total_responses,1);
$pool_percentaje[2] = round((100*$pool_responses[2])/$total_responses,1);
// print the form, which includes de answers and the percentajes
print "<center>\n";
print "<form method=post action=".$_SERVER["PHP_SELF"].">\n";
print "<b>".$pool_question."</b>\n";
print "<table cellpadding=4>\n";
// answer 1
print "<tr>\n";
print "<td><input type=radio name=7680777 value=1> ".$pool_option[1]."</td>\n";
print "<td bgcolor=DDDDFF>".$pool_responses[1]." (".$pool_percentaje[1]."%)</td>\n";
print "</tr>\n";
// answer 2
print "<tr>\n";
print "<td><input type=radio name=7680777 value=2> ".$pool_option[2]."</td>\n";
print "<td bgcolor=DDDDFF>".$pool_responses[2]." (".$pool_percentaje[2]."%)</td>\n";
print "</tr>\n";
print "</table>\n";
// a simple control to avoid one user to vote several times
if ($_POST["7680777"]){
print "<input type=hidden name=7680777b value=1>\n";
}
print "<input TYPE=submit value=Add my answer>\n";
print "</form>\n";
print "</center>\n";
?>