Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,098
    Thanks
    297
    Thanked 12 Times in 12 Posts

    Exclamation recent php upgrade has stoped part of my rating script from working.

    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

    Code:
    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
    PHP Code:
    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==$added=$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 >= && $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

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    $_REQUEST is no longer supported.

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

  • #3
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,098
    Thanks
    297
    Thanked 12 Times in 12 Posts
    ah ok here is the js file which seems to set those values, not sure if its a get or post thought

    Code:
    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
    Code:
    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

  • #4
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,098
    Thanks
    297
    Thanked 12 Times in 12 Posts
    $_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

  • #5
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    Code:
    xmlhttp.open('get', 'rpc.php?j='+vote+'&q='+id_num+'&t='+ip_num+'&c='+units);
    It's sending the request via GET.
    John

  • #6
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,098
    Thanks
    297
    Thanked 12 Times in 12 Posts
    cheers John! have updated that now.

    still wont show the ratings as the user selects them

    cheers
    Last edited by LJackson; 02-05-2010 at 02:51 PM.

  • #7
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by mlseim View Post
    $_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...es.request.php

  • #8
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    @MattF> The page you've linked specifies that 5.3.0 changed the order, but I don't see anything mentioning that either.

  • #9
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,098
    Thanks
    297
    Thanked 12 Times in 12 Posts
    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

  • #10
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,098
    Thanks
    297
    Thanked 12 Times in 12 Posts
    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
    Code:
    .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
    PHP Code:
    '<div class="loading"></div>'
    where should i place it?

    thanks
    Luke
    Last edited by LJackson; 02-05-2010 at 02:39 PM.

  • #11
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,098
    Thanks
    297
    Thanked 12 Times in 12 Posts
    ok found this in the js file
    Code:
    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

  • #12
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Please ask a moderator to merge this new topic into a new thread in the JavaScript forum.

  • #13
    Regular Coder
    Join Date
    Mar 2006
    Posts
    238
    Thanks
    3
    Thanked 37 Times in 37 Posts
    Quote Originally Posted by mlseim View Post
    $_REQUEST is no longer supported.
    2 Mlseim: It seems this information is not really correct. According to the Manual $_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.
    Last edited by SKDevelopment; 02-05-2010 at 03:48 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •