Okay, er vist gået glip af nogle posts her... Det er et rating-script, jeg har fundet ude på nettet og altså ikke forfattet selv. Hele script.php ser netop nu således ud:
<?php
foreach($_GET AS $key => $value) {
${$key} = $value;
}
foreach($_POST AS $key => $value) {
${$key} = $value;
}
$ip=getenv(remote_addr);
//$ip=rand(1,10000); //Enable it to disable IP logging
include "conf.php";
$link1=getenv(HTTP_HOST);
$link2=$_SERVER["PHP_SELF"];
$link="
http://$link1$link2";$blink=str_replace("script.php","",$link);
$db=mysql_connect($db_host,$database_user,$database_pass) or die("<b>MySQL Error:</b> Unable to connect to database please check that you have provided the correct <li>Database Login username<li>Database Login Password"); //Connect to database or give error if failed
mysql_select_db($db_name,$db)or die("<b>MySQL Error:</b> Unable to select database please check that you have provided the correct <li>Database name");
$id=str_replace("..","",$id);
$id=str_replace("<","",$id);
$id=str_replace(">","",$id);
$id=str_replace("'","",$id);
$id=str_replace("&","",$id);
$id=str_replace("%","",$id);
$id=str_replace("^","",$id);
$id=str_replace("$","",$id);
$id=str_replace("\\","",$id);
$id=str_replace("/","",$id);
$id=str_replace("(","",$id);
$st=str_replace("..","",$st);
$st=str_replace("<","",$st);
$st=str_replace(">","",$st);
$st=str_replace("'","",$st);
$st=str_replace("&","",$st);
$st=str_replace("%","",$st);
$st=str_replace("^","",$st);
$st=str_replace("$","",$st);
$st=str_replace("\\","",$st);
$st=str_replace("/","",$st);
$st=str_replace("(","",$st);
if($_REQUEST['rate']){
if($_REQUEST['rate']>=1){
$sel=mysql_query("SELECT * FROM rating_ajx WHERE tm='$id'");
if(mysql_num_rows($sel)==1){
$row=@mysql_fetch_array($sel);
if($row[ip]==$ip){
$new_stats=$row[votes];
$new_aveg=$row[rating];
}else{
$new_aveg=(($row[rating]*$row[votes])+$rate)/($row[votes]+1);
$new_stats=$row[votes]+1;
$upd=mysql_query("UPDATE rating_ajx SET ip='$ip',votes='$new_stats',rating='$new_aveg' WHERE tm='$id'");
}
}else{
$new_stats=1;
$new_aveg=$_REQUEST['rate'];
$upd=mysql_query("INSERT INTO rating_ajx SET ip='$ip',votes='$new_stats',rating='$new_aveg',tm='$id'");
}
}else{
$seli=mysql_query("SELECT * FROM rating_ajx WHERE tm='$id'");
$bow=@mysql_fetch_array($seli);
$new_stats=$bow[votes];
$new_aveg=$bow[rating];
}
$new_aveg=round($new_aveg,2);
if($new_stats>1){
$spell="votes";
}else{
$spell="vote";
}
echo "<FONT SIZE=1><B>Average: $new_aveg ($new_stats $spell)</B></FONT>";
}else{
echo "var xmlhttp;";
echo "
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
} else if(window.ActiveXObject) {
xmlhttp = new ActiveXObject(\"Microsoft.XMLHTTP\");
}
var shows = 0;
var rid;
var lc;
";
echo "function load(rate,rid){
lc=rid;
var qs = '".$blink."script.php?id='+rid+'&rate='+rate;
xmlhttp.open(\"POST\", qs);
xmlhttp.onreadystatechange = handleResponse;
xmlhttp.send(null);
}
function notext (raid)
{
var cy;
var poy;
cy = 'imgst'+raid;
poy = document.getElementById(cy);
poy.innerHTML='';
}
function show(star_img,rnid,style)
{
if (shows){
if(rnid==lc){
return;
}
};
var i;
var image;
var ny;
var cy;
var poy;
cy = 'imgst'+rnid;
poy = document.getElementById(cy);
for (i=1; i<=star_img; i++) {
image = 'qw'+rnid + i;
ny = document.getElementById(image);
ny.src=\"".$blink."style/\"+style+\"/over.gif\";
if(i=='1'){
poy.innerHTML='Poor';
}
else if(i=='2'){
poy.innerHTML='Fair';
}
else if(i=='3'){
poy.innerHTML='Good';
}
else if(i=='4'){
poy.innerHTML='Very Good';
}
else if(i=='5'){
poy.innerHTML='Excellent';
}
}
}
function noshow(star_img,rnid,style)
{
if (shows){
if(rnid==lc){
return;
}
};
var i;
var image;
var ny;
for (i=1; i<=5; i++) {
image = 'qw'+rnid + i;
ny = document.getElementById(image);
ny.src=\"".$blink."style/\"+style+\"/out.gif\";
}
for (i=1; i<=star_img; i++) {
image = 'qw'+rnid + i;
ny = document.getElementById(image);
ny.src=\"".$blink."style/\"+style+\"/out.gif\";
}
//check(rnid,style);
}";
echo "function check(doc,rnid,style){";
echo "for (var i=1; i<=5; i++) {";
echo "var image; var ny;";
echo "image = 'qw'+rnid + i;";
echo "ny = document.getElementById(image);";
echo "if(i<=doc){";
echo "ny.src=\"".$blink."style/\"+style+\"/over.gif\";";
echo "}else{";
echo "ny.src=\"".$blink."style/\"+style+\"/out.gif\";";
echo "}";
echo "} }";
echo "function mark(star_img,rid,style)
{
if (shows){
if(rid==lc){
return;
}
};
show(star_img,rid,style);
shows = 1;
lc=rid;
//var n = document.getElementById('n'+rid);
//n.innerHTML = \"Thank you for rating\";
var qs = '".$blink."script.php?rate=' + star_img + '&id='+rid+'&st='+style;
xmlhttp.open(\"POST\", qs);
xmlhttp.onreadystatechange = handleResponse1;
xmlhttp.send(null);
}
function handleResponse() {
if(xmlhttp.readyState == 4){
var response = xmlhttp.responseText;
document.getElementById(lc).innerHTML = response;
}";
echo "}";
echo "function handleResponse1() {
if(xmlhttp.readyState == 4){
var response = xmlhttp.responseText;
document.getElementById(lc).innerHTML = response;
}";
echo "}";
echo "
function showform(raid,style){";
$sekl=mysql_query("SELECT * FROM rating_ajx WHERE tm='$id'");
if(@mysql_num_rows($sekl)==1){
$riw=@mysql_fetch_array($sekl);
}
if($riw[rating]==""){
$riw[rating]=0;
}
echo "var doc=\"$riw[rating]\";";
echo "document.write(\"<Table width=180 border=0 cellpadding=0 cellspacing=0><TR><TD width=180 colspan=2 style='FONT-FAMILY: Verdana, Arial;font-size:12px;'><span id=n\"+raid+\"></span></TD></TR><TR><TD width=115 style='padding:0px;'><span id=povc>\");
var i;
for (i=1; i<=5; i++) {";
echo "if(i<=doc){";
echo "document.write(\"<img src='".$blink."/style/\"+style+\"/over.gif' id=qw\"+raid+i+\" onmouseover='noshow(\"+i+\",\"+raid+\",\"+style+\");show(\"+i+\",\"+raid+\",\"+style+\")' onmouseout='noshow(\"+i+\",\"+raid+\",\"+style+\");notext(\"+raid+\");check(\"+doc+\",\"+raid+\",\"+style+\");' onclick='mark(\"+i+\",\"+raid+\",\"+style+\")'>\");";
echo "}else{";
echo "document.write(\"<img src='".$blink."style/\"+style+\"/out.gif' id=qw\"+raid+i+\" onmouseover='noshow(\"+i+\",\"+raid+\",\"+style+\");show(\"+i+\",\"+raid+\",\"+style+\")' onmouseout='noshow(\"+i+\",\"+raid+\",\"+style+\");notext(\"+raid+\");check(\"+doc+\",\"+raid+\",\"+style+\");' onclick='mark(\"+i+\",\"+raid+\",\"+style+\")'>\");";
echo "}";
echo "
}
document.write(\"</span></TD><td width=65 align=left style='font-size:10px;padding-left:2px;FONT-FAMILY: Verdana, Arial;'><span id=imgst\"+raid+\"></span></TD></TR><TR><TD colspan=2 style='FONT-FAMILY: Verdana, Arial;'><span id=\"+raid+\"></span></TD></TR></Table>\");
}
";
}
?>
Var der nogen, der blev klogere af det?