View Full Version : Getting stream instead of html

31st October 2006, 17:02

I try to connect this shoutcast server
from my php page using fsockopen function. As response I receive html code from the server, not stream. But if I enter this link in Winamp, it starts buffering and playing the stream.

How can I get this stream in my web page instead of html text message, like in Winamp? Any ideas?

Thanks for help.

31st October 2006, 17:18
Pass mozilla in the beginning of the User-Agent string.

31st October 2006, 18:05
I already did this in my http request. But it did not work.

This is the code:

//connection function
function http_fsearch ($host, $path, $port = 80) {
$conn_host = $host;
$conn_port = $port;

//set real URL
$conn_url = "http://$host:$port$path";

//create connection query
$query = "GET $path HTTP/1.1\r\n" .
"Accept: audio/mpeg mp3, */*\r\n" .
"Host: $host:$port\r\n" .
"Connection: Keep-Alive\r\n" .
"User-Agent: Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)\r\n" .

//open the server
$fp = fsockopen($conn_host, $conn_port);
if (!$fp) die("$errstr ($errno)\n");

if (!$fp) { //connection error
return false;
} else {
//send the query
fputs($fp, $query);
//receive results
return $fp;

//main code

$url = "";
$urldata = parse_url($url);
if (!$urldata["port"]) {
$urldata["port"] = 80;
if (!$urldata["path"]) {
$urldata["path"] = "/";
//check if host is ip address
$isp = explode('.', $urldata["host"]);
$myisp = $isp[1].'.'.$isp[0];
if (preg_match("/[0-9]{1,3}\.[0-9]{1,3}/", $myisp)) {
$host = gethostbyaddr($urldata["host"]);//ip
} else {
$host = $urldata["host"]; //host
//connecting to server
$fp = http_fsearch($host, $urldata["path"], $urldata["port"]);

if (!$fp) {
echo("Error: your request is not accepted.");
} else {
while (!feof($fp)) {
$line = fgets($fp, 1024);
echo ($line);

And all that I have is only html text from the server, not stream.
BTW if I use this link
$url = "http://scfire-chi0l-2.stream.aol.com:80/stream/1048";
it returns me stream music.

31st October 2006, 18:08
Ahh.. that's because that isn't a normal SHOUTcast stream, it uses AOL's Ultravox. It doesn't have a publicly available status page.

31st October 2006, 18:18
But how can I get this real stream for "normal" shoucast server instead of its status page? Is it possible to do inside web page? How can winamp connect to such a server and get the stream?

31st October 2006, 18:25
Okay, misread the original post. If you want the stream and not the HTML, just drop the user-agent string all together. Or just change it to something that doesn't begin with Mozilla.

31st October 2006, 18:33
Sawg, you are the man!!

I put this line "User-Agent: PHP/class http 0.1\r\n" and it is working now.

Thanks a lot!!!

1st November 2006, 02:15
if you open a URL with winamp is ASSUMES its the stream address so using it would connect to tune in, also real media, and windows media player.

~ D