Hierbij de req.php uit de map req:
Code: Selecteer alles
<?
Def($samhost,$sam["host"]);
Def($samport,$sam["port"]);
Def($dedicated,false);
if(empty($samhost)) DoError(800);
//if(($samhost=="127.0.0.1") OR ($samhost=="localhost")) DoError(801);
$songid = isset($_GET['songid']) && is_numeric($_GET['songid']) ? $_GET['songid'] : DoError(802);
;
settype($songid,"integer"); //Make sure songID is an integer to avoid SQL injection
$host = $_SERVER["REMOTE_ADDR"];
$request = "GET /req/?songID=".$songid."&host=".urlencode($_SERVER['REMOTE_ADDR'])." HTTP\1.0\r\n\r\n";
$xmldata = "";
$fd = @fsockopen($samhost,$samport, $errno, $errstr, 30);
//$fd = fopen("http://$samhost:$samport/req/?songID=$songID&host=".urlencode($host),"r");
//echo "fd=$fd";
if(!empty($fd))
{
fputs ($fd, $request);
$line="";
while(!($line=="\r\n"))
{ $line=fgets($fd,128); } // strip out the header
while ($buffer = fgets($fd, 4096))
{ $xmldata .= $buffer; }
fclose($fd);
}
else DoError(803);
if(empty($xmldata)) DoError(804);
//$xmldata = File2Str($url);
//Header("Content-type:text/xml");
// echo $xmldata;
//#################################
// Initialize data
//#################################
$tree = XML2Array($xmldata);
$request = Keys2Lower($tree["REQUEST"]);
$code = $request["status"]["code"];
$message = $request["status"]["message"];
$requestid = $request["status"]["requestid"];
if(empty($code)) DoError(804);
if($requestid>0)
{
/*== If your database is located on a remote host, you must specify local SAM login details here ===*/
$db = new DBTable();
$db->connect($samlogin);
$db->open("SELECT songlist.*, songlist.ID as songID FROM requestlist, songlist
WHERE (songlist.ID = requestlist.songID) AND (requestlist.ID = $requestid)",1);
if($song=$db->row())
{
if(!isset($song["songid"])) $song["songid"]=0;
$song["requestid"] = $requestid;
PrepareSong($song);
}
}
if($code==200)
require("req/req.success.html");
else
require("req/req.failed.html");
function DoError($code)
{
global $samhost, $samport, $errno, $errstr;
switch ($code)
{
case 800 : $message = "SAM host must be specified"; break;
case 801 : $message = "SAM host can not be 127.0.0.1 or localhost"; break;
case 802 : $message = "Song ID must be valid"; break;
case 803 : $message = "Unable to connect to $samhost:$samport. Station might be offline.<br>The error returned was $errstr ($errno)."; break;
case 804 : $message = "Invalid data returned!"; break;
}
require("req/req.failed.html");
exit;
}
?>
en de dedication.form:
Code: Selecteer alles
<table border="0">
<tr><td nowrap><img src="images/im.gif"
width="16" height="16" align="absmiddle" border="0"> <font size=2><b>Dedications</b></font><br></td></tr>
<tr>
<td><p class="bodycopy">Would you like to dedicate your
request to somebody?</td>
</tr>
<tr>
<td>
<form method="POST" action="req.php">
<? InputHidden("requestid",$song["requestid"],0); ?>
<? InputHidden("songid",$song["songid"],0); ?>
<p class="bodycopy"><img src="images/arrow.gif" width="14"
height="9"> Your name:<br>
<input type="text" name="rname" size="30"></p>
<p class="bodycopy"><img src="images/arrow.gif"
width="14" height="9""> Your message<br>
<textarea rows="4" name="rmessage" cols="24"></textarea><br>
<input type="submit" value="Dedicate it!" name="B1"></p>
</form>
</td>
</tr>
</table>
Alvast bedankt voor je moeite!!