...

View Full Version : recent php upgrade has stoped part of my rating script from working.



LJackson
02-04-2010, 11:52 PM
Hi All

my host recently upgaded to php 5.3 and since then my rating script has stopped working correctly,

it still counts the votes etc but it doesnt show the user the value they have voted once they click on the rating, which can be very confusing to the user a
i have asked over in the js forum for the guys to check out my js code to see if there is anything wrong with that and i thought i'd check out my php files associated with this script

so i opened up one of the php files in my browser and i got some errors on the screen, now im not sure if this is because the rest of the script hasnt been run first etc but here are the errors im getting


Notice: Undefined index: j in /customers/kernow-connect.com/kernow-connect.com/httpd.www/rpc.php on line 21

Notice: Undefined index: q in /customers/kernow-connect.com/kernow-connect.com/httpd.www/rpc.php on line 22

Notice: Undefined index: t in /customers/kernow-connect.com/kernow-connect.com/httpd.www/rpc.php on line 23

Notice: Undefined index: c in /customers/kernow-connect.com/kernow-connect.com/httpd.www/rpc.php on line 24

Notice: Undefined variable: rating_unitwidth in /customers/kernow-connect.com/kernow-connect.com/httpd.www/rpc.php on line 67

Notice: Undefined variable: rating_unitwidth in /customers/kernow-connect.com/kernow-connect.com/httpd.www/rpc.php on line 68
unit_long|

and here is my php file

header("Cache-Control: no-cache");
header("Pragma: nocache");

require('dbinfo.php'); // get the db connection info
$rating_unitwidth = "";
//getting the values
$vote_sent = preg_replace("/[^0-9]/","",$_REQUEST['j']);
$id_sent = preg_replace("/[^0-9a-zA-Z]/","",$_REQUEST['q']);
$ip_num = preg_replace("/[^0-9\.]/","",$_REQUEST['t']);
$units = preg_replace("/[^0-9]/","",$_REQUEST['c']);
$ip = $_SERVER['REMOTE_ADDR'];

if ($vote_sent > $units) die("Sorry, vote appears to be invalid."); // kill the script because normal users will never see this.


//connecting to the database to get some information
$query = mysql_query("SELECT total_votes, total_value, used_ips FROM temp WHERE id='$id_sent' ")or die(" Error: ".mysql_error());
$numbers = mysql_fetch_assoc($query);
$checkIP = unserialize($numbers['used_ips']);
$count = $numbers['total_votes']; //how many votes total
$current_rating = $numbers['total_value']; //total number of rating added together and stored
$sum = $vote_sent+$current_rating; // add together the current vote value and the total vote value
$tense = ($count==1) ? "vote" : "votes"; //plural form votes/vote

// checking to see if the first vote has been tallied
// or increment the current number of votes
($sum==0 ? $added=0 : $added=$count+1);

// if it is an array i.e. already has entries the push in another value
((is_array($checkIP)) ? array_push($checkIP,$ip_num) : $checkIP=array($ip_num));
$insertip=serialize($checkIP);

//IP check when voting
$voted=mysql_num_rows(mysql_query("SELECT used_ips FROM temp WHERE used_ips LIKE '%".$ip."%' AND id='".$id_sent."' "));
if(!$voted) { //if the user hasn't yet voted, then vote normally...

if (($vote_sent >= 1 && $vote_sent <= $units) && ($ip == $ip_num)) { // keep votes within range, make sure IP matches - no monkey business!
$update = "UPDATE temp SET total_votes='".$added."', total_value='".$sum."', used_ips='".$insertip."' WHERE id='$id_sent'";
$result = mysql_query($update);
}
} //end for the "if(!$voted)"
// these are new queries to get the new values!
$newtotals = mysql_query("SELECT total_votes, total_value, used_ips FROM temp WHERE id='$id_sent' ")or die(" Error: ".mysql_error());
$numbers = mysql_fetch_assoc($newtotals);
$count = $numbers['total_votes'];//how many votes total
$current_rating = $numbers['total_value'];//total number of rating added together and stored
$tense = ($count==1) ? "vote" : "votes"; //plural form votes/vote

// $new_back is what gets 'drawn' on your page after a successful 'AJAX/Javascript' vote

$new_back = array();

$new_back[] .= '<ul class="unit-rating" style="width:'.$units*$rating_unitwidth.'px;">';
$new_back[] .= '<li class="current-rating" style="width:'.@number_format($current_rating/$count,2)*$rating_unitwidth.'px;">Current rating.</li>';
$new_back[] .= '<li class="r1-unit">1</li>';
$new_back[] .= '<li class="r2-unit">2</li>';
$new_back[] .= '<li class="r3-unit">3</li>';
$new_back[] .= '<li class="r4-unit">4</li>';
$new_back[] .= '<li class="r5-unit">5</li>';
$new_back[] .= '<li class="r6-unit">6</li>';
$new_back[] .= '<li class="r7-unit">7</li>';
$new_back[] .= '<li class="r8-unit">8</li>';
$new_back[] .= '<li class="r9-unit">9</li>';
$new_back[] .= '<li class="r10-unit">10</li>';
$new_back[] .= '</ul>';
$new_back[] .= '<p class="voted">'.$id_sent.'. Rating: <strong>'.@number_format($sum/$added,1).'</strong>/'.$units.' ('.$count.' '.$tense.' cast) ';
$new_back[] .= '<span class="thanks">Thanks for voting!</span></p>';

$allnewback = join("\n", $new_back);

// ========================

//name of the div id to be updated | the html that needs to be changed
$output = "unit_long$id_sent|$allnewback";
echo $output;


does this look correct for php 5.3?

thanks all
Luke

mlseim
02-05-2010, 12:15 AM
$_REQUEST is no longer supported.

You have to specify either $_GET or $_POST, depending on which it is supposed to be.

LJackson
02-05-2010, 12:19 AM
ah ok here is the js file which seems to set those values, not sure if its a get or post thought :)


var xmlhttp
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
} catch (e) {
try {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
} catch (E) {
xmlhttp=false
}
}
@else
xmlhttp=false
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp=false
}
}
function myXMLHttpRequest() {
var xmlhttplocal;
try {
xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP")
} catch (e) {
try {
xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP")
} catch (E) {
xmlhttplocal=false;
}
}

if (!xmlhttplocal && typeof XMLHttpRequest!='undefined') {
try {
var xmlhttplocal = new XMLHttpRequest();
} catch (e) {
var xmlhttplocal=false;
alert('couldn\'t create xmlhttp object');
}
}
return(xmlhttplocal);
}

function sndReq(vote,id_num,ip_num,units) {
var theUL = document.getElementById('unit_ul'+id_num); // the UL

// switch UL with a loading div
theUL.innerHTML = '<div class="loading"></div>';

xmlhttp.open('get', 'rpc.php?j='+vote+'&q='+id_num+'&t='+ip_num+'&c='+units);
xmlhttp.onreadystatechange = handleResponse;
xmlhttp.send(null);
}

function handleResponse() {
if(xmlhttp.readyState == 4){
if (xmlhttp.status == 200){

var response = xmlhttp.responseText;
var update = new Array();

if(response.indexOf('|') != -1) {
update = response.split('|');
changeText(update[0], update[1]);
}
}
}
}

function changeText(div2show,text) {
var viewer = document.getElementById(div2show);
viewer.innerHTML = text;
}
/* =============================================================== */
var ratingAction = {
'a.rater' : function(element){
element.onclick = function(){

var parameterString = this.href.replace(/.*\?(.*)/, "$1"); // onclick="sndReq('j=1&q=2&t=127.0.0.1&c=5');
var parameterTokens = parameterString.split("&"); // onclick="sndReq('j=1,q=2,t=127.0.0.1,c=5');
var parameterList = new Array();

for (j = 0; j < parameterTokens.length; j++) {
var parameterName = parameterTokens[j].replace(/(.*)=.*/, "$1"); // j
var parameterValue = parameterTokens[j].replace(/.*=(.*)/, "$1"); // 1
parameterList[parameterName] = parameterValue;
}
var theratingID = parameterList['q'];
var theVote = parameterList['j'];
var theuserIP = parameterList['t'];
var theunits = parameterList['c'];

//for testing alert('sndReq('+theVote+','+theratingID+','+theuserIP+','+theunits+')'); return false;
sndReq(theVote,theratingID,theuserIP,theunits); return false;
}
}

};
Behaviour.register(ratingAction);


specifically this bit

function sndReq(vote,id_num,ip_num,units) {
var theUL = document.getElementById('unit_ul'+id_num); // the UL

// switch UL with a loading div
theUL.innerHTML = '<div class="loading"></div>';

xmlhttp.open('get', 'rpc.php?j='+vote+'&q='+id_num+'&t='+ip_num+'&c='+units);
xmlhttp.onreadystatechange = handleResponse;
xmlhttp.send(null);
}


i think that is what is setting those values?

cheers
Luke

LJackson
02-05-2010, 12:33 AM
$_GET seems to do the same as $_request.

the odd thing is that the rating is being counted but not being shown unless i press the refresh button then the star value is shown.

any other ideas mate
cheers
Luke

PappaJohn
02-05-2010, 12:33 AM
xmlhttp.open('get', 'rpc.php?j='+vote+'&q='+id_num+'&t='+ip_num+'&c='+units);

It's sending the request via GET.

LJackson
02-05-2010, 12:41 AM
cheers John! have updated that now.

still wont show the ratings as the user selects them

cheers

MattF
02-05-2010, 12:42 AM
$_REQUEST is no longer supported.

Do you have a link to where that's mentioned? Can't find any reference to it being deprecated on the php site.

http://uk.php.net/manual/en/reserved.variables.request.php

bdl
02-05-2010, 02:42 AM
@MattF> The page you've linked specifies that 5.3.0 changed the order (http://uk.php.net/manual/en/ini.core.php#ini.request-order), but I don't see anything mentioning that either.

LJackson
02-05-2010, 02:44 PM
have sorted it now guys thanks, used firebug to check the js and it showed that one of the varibles was not defined, and defining it sorted the problem :)

cheers
Luke

LJackson
02-05-2010, 03:37 PM
does anyone know how i can add a little animation next to the rating to show that its processing as sometimes it can take a few seconds to show the new rating, just so the user knows something is happening :)

i have this in my css

.loading {
height: 20px;
background: url('../images/working.gif') 50% 50% no-repeat;
}

but can see where the loading class is being used, or maybe its not?

i have tried adding it but no image shows

'<div class="loading"></div>';

where should i place it?

thanks
Luke

LJackson
02-05-2010, 03:43 PM
ok found this in the js file

function sndReq(vote,id_num,ip_num,units) {
var theUL = document.getElementById('unit_ul'+id_num); // the UL

// switch UL with a loading div
theUL.innerHTML = '<div class="loading"></div>';

xmlhttp.open('get', 'rpc.php?j='+vote+'&q='+id_num+'&t='+ip_num+'&c='+units);
xmlhttp.onreadystatechange = handleResponse;
xmlhttp.send(null);
}


which seems to suggest showing the loading image, so what is preventing it from loading?

any ideas
Luke

bdl
02-05-2010, 04:12 PM
Please ask a moderator to merge this new topic into a new thread in the JavaScript forum.

SKDevelopment
02-05-2010, 04:42 PM
$_REQUEST is no longer supported.

2 Mlseim: It seems this information is not really correct. According to the Manual (http://www.php.net/manual/en/reserved.variables.request.php) $_REQUEST is perfectly supported by PHP 5.3. But the directive request_order is introduced which describes the order in which PHP registers GET, POST and Cookie variables into the $_REQUEST array. Maybe you meant something different?

I am sorry to the OP for the off-topic.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum