PDA

View Full Version : php help



chq
06-08-2009, 12:58 PM
hello to any php experts on bw

i need some help on editing 2 php files?

Lloyd
06-08-2009, 01:02 PM
post them here, lets have a look at them.

Ill see what i can do

chq
06-08-2009, 01:17 PM
Now Playing script:


<?php
/* ---------- General configuration ---------- */

$station_name = "";

$refresh = "0"; // Page refresh time in seconds. Put 0 for no refresh
$timeout = "5"; // Number of seconds before connecton times out - a higher value will slow the page down if any servers are offline

/* ----------- Server configuration ---------- */

// Note: dont include http://
// Main server: The song title will be taken from this server



$ip[1] = "";
$port[1] = "";


/* ----- No need to edit below this line ----- */
/* ------------------------------------------- */
$servers = count($ip);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?php
if ($refresh != "0")
{
print "<meta http-equiv=\"refresh\" content=\"$refresh\">\n";
}
print "<title>$station_name Stats</title>\n";
?>
</head>
<body><center>
<?php
$i = "1";
while($i<=$servers)
{
$fp = @fsockopen($ip[$i],$port[$i],$errno,$errstr,$timeout);
if (!$fp)
{
$listeners[$i] = "0";
$msg[$i] = "<span class=\"red\">ERROR [Connection refused / Server down]</span>";
$error[$i] = "1";
}
else
{
fputs($fp, "GET /7.html HTTP/1.0\r\nUser-Agent: Mozilla\r\n\r\n");
while (!feof($fp))
{
$info = fgets($fp);
}
$info = str_replace('<HTML><meta http-equiv="Pragma" content="no-cache"></head><body>', "", $info);
$info = str_replace('</body></html>', "", $info);
$stats = explode(',', $info);
if (empty($stats[1]) )
{
$listeners[$i] = "0";
$msg[$i] = "<span class=\"red\">ERROR [There is no source connected]</span>";
$error[$i] = "1";
}
else
{
if ($stats[1] == "1")
{
$song[$i] = $stats[6];
$listeners[$i] = $stats[0];
$max[$i] = $stats[3];
$bitrate[$i] = $stats[5];
$peak[$i] = $stats[2];
if ($stats[0] == $max[$i])
{
$msg[$i] .= "<span class=\"red\">";
}
$msg[$i] .= "Server is up at $bitrate[$i] kbps with $listeners[$i] of $max[$i] listeners";
if ($stats[0] == $max[$i])
{
$msg[$i] .= "</span>";
}
$msg[$i] .= "\n <p><b>Listener peak:</b> $peak[$i]";
}
else
{
$listeners[$i] = "0";
$msg[$i] = " <span class=\"red\">ERROR [Cannot get info from server]</span>";
$error[$i] = "1";
}
}
}
$i++;
}
$total_listeners = array_sum($listeners) ;
print "<a href=\"radio.pls\"><center><b>Now Playing:</b> $song[1]</center></a>";
?>
</center>
</body>
</html>
banner ad rotation:


<?
$bannerCounter= 1;


$bannerCode[$bannerCounter] = "<a href=\"http://cyba.fm/djprofiles\" target=\"_top\"> <img src=\"http://cyba.fm/adds/ff.gif\" width=\"468\" height=\"80\" alt=\"Fused Forces Wed 8-10pm\" border=\"0\"></a>";
$bannerCounter++;

$bannerCode[$bannerCounter] = "<a href=\"http://cyba.fm/djprofiles\" target=\"_top\"> <img src=\"http://cyba.fm/adds/doh.gif\" width=\"468\" height=\"80\" alt=\"DohZa Tue 8-10pm\" border=\"0\"></a>";
$bannerCounter++;


$bannerAdTotals = $bannerCounter - 1;
if($bannerAdTotals>1)
{
mt_srand((double)microtime() * 1234567);
$bannerPicked = mt_rand(1, $bannerAdTotals);
}
else
{
$bannerPicked = 1;
}
$bannerAd = $bannerCode[$bannerPicked];
?>
im in the process of rebuilding my radio website and i decided to go the
extra mile by bring the site to w3c standards.
ive managed to fix loads of errors already but im have trouble with theses
2 php files.
the html that php files produces or not up to w3c standards and im not sure on how to bring them up to that standard?

Brutish Sailor
06-08-2009, 04:49 PM
now playing script for cybaFM:

<script type="text/javascript" src="http://cdn.widgetserver.com/syndication/subscriber/InsertWidget.js"></script><script>if (WIDGETBOX) WIDGETBOX.renderWidget('e87405de-d540-4463-8e0e-31f122031c78');</script><noscript>Get the <a href="http://www.widgetbox.com/widget/1c81177b-2aad-4150-af8a-ea310014d890">CybaFM</a> widget and many other <a href="http://www.widgetbox.com/">great free widgets</a> at <a href="http://www.widgetbox.com">Widgetbox</a>!</noscript>

chq
06-08-2009, 05:42 PM
now playing script for cybaFM:

<script type="text/javascript" src="http://cdn.widgetserver.com/syndication/subscriber/InsertWidget.js"></script><script>if (WIDGETBOX) WIDGETBOX.renderWidget('e87405de-d540-4463-8e0e-31f122031c78');</script><noscript>Get the <a href="http://www.widgetbox.com/widget/1c81177b-2aad-4150-af8a-ea310014d890">CybaFM</a> widget and many other <a href="http://www.widgetbox.com/">great free widgets</a> at <a href="http://www.widgetbox.com">Widgetbox</a>!</noscript>

thank you Brutish Sailor but its not vaild
http://validator.w3.org/check?uri=http%3A%2F%2Fcyba.fm%2Ftest%2Finteract%2 F;accept=text%2Fhtml%2Capplication%2Fxhtml%2Bxml%2 Capplication%2Fxml%3Bq%3D0.9%2C*%2F*%3Bq%3D0.8;acc ept-language=en-us%2Cen%3Bq%3D0.5;accept-charset=ISO-8859-1%2Cutf-8%3Bq%3D0.7%2C*%3Bq%3D0.7

Brutish Sailor
06-08-2009, 07:13 PM
ok, just Iframe this. I'm going to take the rate of refresh to 30 seconds. Because you do live mixing sets, it should be about 2 minutes apart, and I'll change that later.

http://www.deadawakenradio.com/CybaFM.php

Brutish Sailor
06-08-2009, 07:53 PM
<iframe name="FRAME" src="http://www.deadawakenradio.com/CybaFM.php" allowtransparency="true" scrolling="no" width="450" align="center" frameborder="0" height="40"></iframe>

Send a couple of raver chicks my way and we are square :)

James
06-09-2009, 01:28 AM
Allright, firstly you cannot validate the php code itself. It can only validate what the php outputs.

Can you post a page on your site where you have both these two scripts running and i can help you make the output valid :)

Lloyd
06-09-2009, 03:55 AM
i has a copy of the code that is now valid. Ill edit this when i finds it


<?php

/* ---------- General configuration ---------- */
$station_name = "";
$refresh = "0"; // Page refresh time in seconds. Put 0 for no refresh
$timeout = "5"; // Number of seconds before connecton times out - a higher value will slow the page down if any servers are offline
/* ----------- Server configuration ---------- */
// Note: dont include http://
// Main server: The song title will be taken from this server

$ip[1] = "";
$port[1] = "";

/* ----- No need to edit below this line ----- */
/* ------------------------------------------- */
$servers = count($ip);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?php
if ($refresh != "0")
{
print "<meta http-equiv=\"refresh\" content=\"$refresh\">\n";
}
print "<title>$station_name Stats</title>\n";
?>
</head>
<body><center>
<?php
$i = "1";
while($i<=$servers)
{
$fp = @fsockopen($ip[$i],$port[$i],$errno,$errstr,$timeout);
if (!$fp)
{
$listeners[$i] = "0";
$msg[$i] = "<span class=\"red\">ERROR [Connection refused / Server down]</span>";
$error[$i] = "1";
}
else
{
fputs($fp, "GET /7.html HTTP/1.0\r\nUser-Agent: Mozilla\r\n\r\n");
while (!feof($fp))
{
$info = fgets($fp);
}
$info = str_replace('<HTML><meta http-equiv="Pragma" content="no-cache"></head><body>', "", $info);
$info = str_replace('</body></html>', "", $info);
$stats = explode(',', $info);
if (empty($stats[1]) )
{
$listeners[$i] = "0";
$msg[$i] = "<span class=\"red\">ERROR [There is no source connected]</span>";
$error[$i] = "1";
}
else
{
if ($stats[1] == "1")
{
$song[$i] = $stats[6];
$listeners[$i] = $stats[0];
$max[$i] = $stats[3];
$bitrate[$i] = $stats[5];
$peak[$i] = $stats[2];
if ($stats[0] == $max[$i])
{
$msg[$i] .= "<span class=\"red\">";
}
$msg[$i] .= "Server is up at $bitrate[$i] kbps with $listeners[$i] of $max[$i] listeners";
if ($stats[0] == $max[$i])
{
$msg[$i] .= "</span>";
}
$msg[$i] .= "\n <p><b>Listener peak:</b> $peak[$i]";
}
else
{
$listeners[$i] = "0";
$msg[$i] = " <span class=\"red\">ERROR [Cannot get info from server]</span>";
$error[$i] = "1";
}
}
}
$i++;
}
$total_listeners = array_sum($listeners) ;
print "<a href=\"radio.pls\"><center><b>Now Playing:</b> $song[1]</center></a>";
?>
</center>
</body>
</html>

Try taking out the <center></center> in the bold section.

Edit
link the <?php with the rest of the code. it's seperating for some reason

Lloyd
06-09-2009, 03:57 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.o$>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title></title>
</head>
<body>
<?
$bannerCounter= 1;

$bannerCode[$bannerCounter] = "<a href=\"http://cyba.fm/djprofiles\" target=\"_top\"> <img src=\"http://cyba.fm/adds/ff.gif\" width=\"468\" height=\"80\" alt=\"Fused Forces Wed 8-10pm\" border=\"0\"></a>";
$bannerCounter++;
$bannerCode[$bannerCounter] = "<a href=\"http://cyba.fm/djprofiles\" target=\"_top\"> <img src=\"http://cyba.fm/adds/doh.gif\" width=\"468\" height=\"80\" alt=\"DohZa Tue 8-10pm\" border=\"0\"></a>";
$bannerCounter++;

$bannerAdTotals = $bannerCounter - 1;
if($bannerAdTotals>1)
{
mt_srand((double)microtime() * 1234567);
$bannerPicked = mt_rand(1, $bannerAdTotals);
}
else
{
$bannerPicked = 1;
}
$bannerAd = $bannerCode[$bannerPicked];
?>
</body>
</html>


Both passed validation when i tested them last night. I hope they still work. :|

chq
06-09-2009, 02:43 PM
i has a copy of the code that is now valid. Ill edit this when i finds it


<?php

/* ---------- General configuration ---------- */
$station_name = "";
$refresh = "0"; // Page refresh time in seconds. Put 0 for no refresh
$timeout = "5"; // Number of seconds before connecton times out - a higher value will slow the page down if any servers are offline
/* ----------- Server configuration ---------- */
// Note: dont include http://
// Main server: The song title will be taken from this server

$ip[1] = "";
$port[1] = "";

/* ----- No need to edit below this line ----- */
/* ------------------------------------------- */
$servers = count($ip);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?php
if ($refresh != "0")
{
print "<meta http-equiv=\"refresh\" content=\"$refresh\">\n";
}
print "<title>$station_name Stats</title>\n";
?>
</head>
<body><center>
<?php
$i = "1";
while($i<=$servers)
{
$fp = @fsockopen($ip[$i],$port[$i],$errno,$errstr,$timeout);
if (!$fp)
{
$listeners[$i] = "0";
$msg[$i] = "<span class=\"red\">ERROR [Connection refused / Server down]</span>";
$error[$i] = "1";
}
else
{
fputs($fp, "GET /7.html HTTP/1.0\r\nUser-Agent: Mozilla\r\n\r\n");
while (!feof($fp))
{
$info = fgets($fp);
}
$info = str_replace('<HTML><meta http-equiv="Pragma" content="no-cache"></head><body>', "", $info);
$info = str_replace('</body></html>', "", $info);
$stats = explode(',', $info);
if (empty($stats[1]) )
{
$listeners[$i] = "0";
$msg[$i] = "<span class=\"red\">ERROR [There is no source connected]</span>";
$error[$i] = "1";
}
else
{
if ($stats[1] == "1")
{
$song[$i] = $stats[6];
$listeners[$i] = $stats[0];
$max[$i] = $stats[3];
$bitrate[$i] = $stats[5];
$peak[$i] = $stats[2];
if ($stats[0] == $max[$i])
{
$msg[$i] .= "<span class=\"red\">";
}
$msg[$i] .= "Server is up at $bitrate[$i] kbps with $listeners[$i] of $max[$i] listeners";
if ($stats[0] == $max[$i])
{
$msg[$i] .= "</span>";
}
$msg[$i] .= "\n <p><b>Listener peak:</b> $peak[$i]";
}
else
{
$listeners[$i] = "0";
$msg[$i] = " <span class=\"red\">ERROR [Cannot get info from server]</span>";
$error[$i] = "1";
}
}
}
$i++;
}
$total_listeners = array_sum($listeners) ;
print "<a href=\"radio.pls\"><center><b>Now Playing:</b> $song[1]</center></a>";
?>
</center>
</body>
</html>Try taking out the <center></center> in the bold section.

Edit
link the <?php with the rest of the code. it's seperating for some reason

i removed the center tags and retested still no joy
http://validator.w3.org/check?uri=http%3A%2F%2Fcyba.fm%2Ftest%2Finteract%2 F;accept=text%2Fhtml%2Capplication%2Fxhtml%2Bxml%2 Capplication%2Fxml%3Bq%3D0.9%2C*%2F*%3Bq%3D0.8;acc ept-language=en-gb%2Cen%3Bq%3D0.5;accept-charset=ISO-8859-1%2Cutf-8%3Bq%3D0.7%2C*%3Bq%3D0.7

im gonna test the banner 1 now

chq
06-09-2009, 02:49 PM
Allright, firstly you cannot validate the php code itself. It can only validate what the php outputs.

Can you post a page on your site where you have both these two scripts running and i can help you make the output valid :)

sure thing
http://cyba.fm/test/interact

Brutish Sailor
06-09-2009, 04:05 PM
do you need me to be running this script then? I can go ahead and shut down the php on my server?

chq
06-09-2009, 05:09 PM
do you need me to be running this script then? I can go ahead and shut down the php on my server?

thanks Brutish Sailor
but you can delete it now

Brutish Sailor
06-09-2009, 05:51 PM
will do. No problem Chq. Im still demanding the little candy flipping raver girls that dress like twins.

LOL Just joking.

Lloyd
06-10-2009, 02:25 AM
Odd, http://validator.w3.org/check?uri=http://59.167.90.247/test.php&charset=(detect+automatically)&doctype=Inline&group=0

Thats it tested on my server and it passes first time...

chq
06-10-2009, 09:12 AM
Odd, http://validator.w3.org/check?uri=http://59.167.90.247/test.php&charset=(detect+automatically)&doctype=Inline&group=0 (http://validator.w3.org/check?uri=http://59.167.90.247/test.php&charset=%28detect+automatically%29&doctype=Inline&group=0)

Thats it tested on my server and it passes first time...

hmm that is strange?

also when i try to visit the w3c link above it says 500 internal error!

James
06-10-2009, 09:31 AM
hmm that is strange?

also when i try to visit the w3c link above it says 500 internal error!

sorry for my anger but when php outputs, ITS NOT VALID! :P

[php script] = maybe valid
[output of the php script] = only valid if the code is valid in the container.

Also... Looking at w3c, you have multiple headers and footers on the page! No wonder you are getting errors :biggrinthumb:

Hope this helps!

chq
06-10-2009, 04:07 PM
Also... Looking at w3c, you have multiple headers and footers on the page! No wonder you are getting errors :biggrinthumb:

Hope this helps!

as i said before j

"i did not put them in there"

the php is out putting those extra headers footers etc
if i take out those two scripts then the extra headers, footers disapears then my page becomes vaild

Brutish Sailor
06-10-2009, 07:53 PM
I never understood the importance of W3c.

I have heard people say I have A W3C valid site, and they wouldnt touch it.

6 MONTHS LATER... I would check it, and BING! 110 errors. So it seems W3c is a little overrated.

Just Personal opinion.