Old 17th May 2006, 18:09   #1
Diablosblizz
Member
 
Join Date: Mar 2006
Posts: 68
Error with Last 10 Played:

Hey guys I have a problem with like everything!
Below is the PHP I used for my last 10 or w.e played.

code:
<?php

// last10.php -- get and display last n tracks...
// URL syntax:
// last10.php?host={24.141.133.213}&port={8000}&n={lastN}
//
// {bracketed} items need to be replaced or they will default as below.
//
// I can return Javascript or HTML only.
//

/* keep warnings from our output */
error_reporting(E_ERROR);

// try to get the target from the url...
$host = $_REQUEST[host];
if (!$host) $host = 'YOUR IP GOES HERE'; // adjust as necessary...
$port = $_REQUEST[port];
if (!$port) $port = 8000; // the "default" DNAS PortBase...

$lf = chr(10); // 0x0A [\n]

// The lastN is configurable at the DNAS with, ShowLastSongs= it defaults to 10 and has a maximum of 20
$t_max = $_REQUEST[n];
if (!t_max || $t_max<1 || $t_max>19) $t_max=10;
//19 is the max here because 20=current_track+19

// Return JavaScript or HTML
$jsOutput=FALSE; // TRUE=js | FALSE=HTML

// Let's get /index.html first... to keep this short, there is no code to handle the dnas being down
// or not running, so the script will display nothing in those cases.

$connect_timeout=5;
$success=0;

$fp1 = fsockopen($host, $port, &$errno, &$errstr, $connect_timeout); //open connection
if(!$fp1) { //if this fails, I'm done....
fclose($fp1);
$success++;
} else {
$request="GET /index.html HTTP/1.1\r\nHost:" . $host . ":" . $port . "\r\nUser-Agent: SHOUTcast DNAS Status [index] * (Mozilla/PHP)\r\nConnection: close\r\n\r\n"; //get index.html
fputs($fp1,$request,strlen($request));
$page='';
while(!feof($fp1)) {
$page .= fread($fp1, 16384);
}
fclose($fp1);

// now I have the entire /index.html in $page -- all I want from here is the current track...
// (hint-hint)

$song00 = ereg_replace("</b></td>.*", "", ereg_replace(".*Current Song: </font></td><td><font class=default><b>", "", $page)); // easy, right <img src="images/smilies/smile.gif" border="0" alt="">

// now let's get /played.html... (this is kinda long)
$fp = fsockopen($host, $port, &$errno, &$errstr, $connect_timeout);
if(!$fp) { //if connection could not be made
fclose($fp);
$success++;

} else {
$request="GET /played.html HTTP/1.1\r\nHost: " . $host . ":" . $port . "\r\nUser-Agent: SHOUTcast DNAS Status [played] * (Mozilla/PHP)\r\n"."Connection: close\r\n\r\n";
fputs($fp,$request,strlen($request));
$page='';
while (!feof($fp)) {
$page .= fread($fp, 16384);
}
fclose($fp); //close connection
$played_html=$page;

if ($played_html) {
$played_html= ereg_replace('<x>','|-|',ereg_replace('</tr>','',ereg_replace('</td><td>','<x>',ereg_replace('<tr><td>','',ereg_replace('</tr>','</tr>' . $lf,ereg_replace('-->','--]',ereg_replace('<!--','[!--',ereg_replace('</table><br><br>.*','',ereg_replace('.*<b>Current Song</b></td></tr>','',$played_html)))))))));
$xxn=strlen($played_html);
$r=2;
$t_count=0;
$reading=0;
$track[0]=$song00;
while ($r<$xxn & $t_count<=$t_max){
$cur=substr($played_html,$r,1);
if ($cur==$lf) $reading=0;
if ($reading==1) $track[$t_count] .= $cur;
if ($cur=="|" & substr($played_html,$r-1,1)=="-" & substr($played_html,$r-2,1)=="|") {
$reading=1;
$t_count++;
}
$r++;
}
}
}
}

// I now have $track[0-N] containg the current plus last N tracks...
// Output time...

if ($success==0);

if ($jsOutput) { // JavaScript - used as <script src=...></script>
header('Content-type: text/javascript');
} else { // HTML... (iFrames anyone?)
echo '<HTML>
<HEAD><TITLE>TITLE OF YOUR PAGE HERE - Now Playing: ' . $track[0] . '</title></head>
<BODY><table width="400" style="border-collapse: collapse" border="2" bordercolor="#660000"><tr bgcolor="#c0c0c0"><td>
<table width="100%" border="0" cellpadding="4"><tr><td>
<font face=Verdana sans-serif size=2>';
}

$r=0;
$output_string='';
while ($r<=$t_max){
if ($r==0) $output_string .= 'Now Playing:<br> <b>'.str_replace("'", "'",str_replace('"', '"',$track[$r])).'</b></td></tr></table></td></tr><tr><td><table width="100%" border="0" cellpadding="4"><tr><td><br><font face=Verdana sans-serif size=2><i>Before that you heard:</i><br><br>';
else $output_string .= str_replace("'", "'",str_replace('"', '"',$track[$r])) . '<br>';

$r++;
}

if ($jsOutput) {
echo "document.write('" . $output_string . "');";
} else {
echo $output_string;
echo '</td></tr></table></td></tr></font></td></tr></table></body></html>';
}
?>




Its not working, like I mean it NOTHINGS working. I have NO idea what my radio server IP is anymore, my ISP is changing it on me!!!!!

Please help me!!!!
Diablosblizz is offline   Reply With Quote
Old 17th May 2006, 19:24   #2
hackerdork
Forum King
 
hackerdork's Avatar
 
Join Date: Feb 2006
Location: Earth Circa sometime.
Posts: 3,297
dia, if you dont know you stations IP address how do you expect the script or stream to work

http://www.whatismyip.com BOOKMARK IT! will show you your address currently. since it continues to change DO NOT TURN OFF THE PC CONNECTED TO THE INTERNET, OR THE ROUTER.

Also get yourself a dynamic host address from dynip.com no-ip.com or others, you will need to read their docs on how to setup the host name and run their updates software, then you can replace the ip address in this script with the dynamic host name.

I hope you didnt put this script on a free hosting site, like geoshitty, tripod etc they do not run PHP!

Good luck

~ D

~ According to the ship's log we're down to our last 3000 vomit bags.It'll never be enough.
search the forums! don't PM me on how-to, or ask me to setup you system. you do it so you learn.
hackerdork is offline   Reply With Quote
Old 20th May 2006, 19:19   #3
Diablosblizz
Member
 
Join Date: Mar 2006
Posts: 68
Im currently using AN AWESOME host, that is called Instanthosting.net

It is free, but it does include php.
http://www.habbo-insider.instanthosting.net/test.php <<---Proves it.

No idea what to do.
Diablosblizz is offline   Reply With Quote
Old 20th May 2006, 19:25   #4
hackerdork
Forum King
 
hackerdork's Avatar
 
Join Date: Feb 2006
Location: Earth Circa sometime.
Posts: 3,297
so...

still doesnt fix the problem that your IP address changes for your internet address which is running the stream. so either you have to edit the php script all the time and update the address, or get a dynamic host name.

A dynamic host name (free!!) need software running on your pc, so if and when the ip address changes the update software tells the internet what the new ip address is for the same host. then you dont have to keep editing your script

if you are clueless to what your ip address currecntly is, www.whatismyip.com will show you


~ D

~ According to the ship's log we're down to our last 3000 vomit bags.It'll never be enough.
search the forums! don't PM me on how-to, or ask me to setup you system. you do it so you learn.
hackerdork is offline   Reply With Quote
Old 20th May 2006, 19:53   #5
djSpinnerCee
Forum King
 
djSpinnerCee's Avatar
 
Join Date: Aug 2004
Location: Hollis, Queens/The Bronx, NYC
Posts: 3,555
IP address = host
DNAS Portbase = port

If you can't get this right, NOTHING else will work.
djSpinnerCee is offline   Reply With Quote
Old 20th May 2006, 19:55   #6
hackerdork
Forum King
 
hackerdork's Avatar
 
Join Date: Feb 2006
Location: Earth Circa sometime.
Posts: 3,297
ya since you posted this
Quote:

// try to get the target from the url...
$host = $_REQUEST[host];
if (!$host) $host = 'YOUR IP GOES HERE'; // adjust as necessary...
$port = $_REQUEST[port];
$host='1.2.3.4';
or $host='whatever.no-ip.com';

and so on... if you did edit the script to match, well no duh???

~ According to the ship's log we're down to our last 3000 vomit bags.It'll never be enough.
search the forums! don't PM me on how-to, or ask me to setup you system. you do it so you learn.
hackerdork is offline   Reply With Quote
Old 22nd May 2006, 16:18   #7
Diablosblizz
Member
 
Join Date: Mar 2006
Posts: 68
http://www.habbo-insider.instanthosting.net/thanks.php

Check it out, and add habbo-insider@hotmail.com and tell me when to run it
Diablosblizz is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Shoutcast > Shoutcast Technical Support

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump