Web Hosting Talk







View Full Version : updating old php code


mikey1090
06-12-2006, 01:48 PM
as mentioned in another thread, my .php3 files no longer work....

i ask the supprt why, they say my code is too old....

problem is i dont know what to do.

Here is the php image code from the .php3 file




<?php

$title = urldecode($title);

$data = urldecode($data);

$x = 40;
$y = 30;

$right_margin= 40;

$bar_width = 5;
$total = 0;
$max = 0;

$unit = (($width-$x)-$right_margin) / 100;

$items= explode( "^^",$data);

while (list($key,$item) = each($items))
{
if ($item)
{
$pos = strpos($item, "^");
$value = substr($item,$pos+1,strlen($item));
$total = $total + $value;
}
}

reset($items);

$height = sizeof($items) * ($bar_width + 22);

Header( "Content-type: image/png");

$im = imagecreate($width,$height);

$white=ImageColorAllocate($im,0,128,128);
$yellow=ImageColorAllocate($im,0,0,0);
/*$blue=ImageColorAllocate($im,0,64,128); */
$blue=ImageColorAllocate($im,0,0,0);
$bar= ImageColorAllocate($im,255,255,255);
$barline= ImageColorAllocate($im,255,255,255);
$barback= ImageColorAllocate($im,109,113,115);
$txtwhite= ImageColorAllocate($im,255,255,255);

ImageFilledRectangle($im,0,0,$width,$height,$blue);

$title_x = (imagesx($im)-7.5*strlen($title))/2;
ImageString($im,3,$title_x,4,$title,$txtwhite);


/*ImageString($im,1,$width-350,17,'',$txtwhite);*/

/*Imageline($im,$x,$y-5,$x,$height-15,$barline);*/

while (list($key,$item) = each($items))
{
if ($item)
{
$pos = strpos($item, "^");
$item_title = substr($item,0,$pos);
$value = substr($item,$pos+1,strlen($item));

ImageString($im,3,$x-25,$y-2,intval(round(($value/$total)*100)). "%",$yellow);


$px = $x + ( intval(round(($value/$total)*100)) * $unit);

ImageFilledRectangle($im,$x,$y-2,$px,$y+$bar_width-5,$barline);
ImageString($im,2,$x+5,$y+9,$item_title,$txtwhite);
ImageFilledRectangle($im,$px+1,$y-2,($x+(100*$unit)),$y+$bar_width-6,$barback);

/*ImageString($im,1,($x+(100*$unit))-40,$y+12,$value. "/".$total,$bar); */
ImageString($im,2,($x+(100*$unit))-strlen(strval($value))-$bar_width-45,$y+12,$value. "/".$total,$txtwhite);

}
$y=$y+($bar_width+20);
}


ImagePng($im);
ImageDestroy($im);
?>




here is the error it gives....


br />
<b>Warning</b>: imagecreate(): Invalid image dimensions in <b>/home/zorg1090/public_html/mike/graphic.php3</b> on line <b>39</b><br />
<br />
<b>Warning</b>: imagecolorallocate(): supplied argument is not a valid Image resource in <b>/home/zorg1090/public_html/mike/graphic.php3</b> on line <b>42</b><br />
<br />
<b>Warning</b>: imagecolorallocate(): supplied argument is not a valid Image resource in <b>/home/zorg1090/public_html/mike/graphic.php3</b> on line <b>43</b><br />
<br />
<b>Warning</b>: imagecolorallocate(): supplied argument is not a valid Image resource in <b>/home/zorg1090/public_html/mike/graphic.php3</b> on line <b>45</b><br />
<br />
<b>Warning</b>: imagecolorallocate(): supplied argument is not a valid Image resource in <b>/home/zorg1090/public_html/mike/graphic.php3</b> on line <b>46</b><br />
<br />
<b>Warning</b>: imagecolorallocate(): supplied argument is not a valid Image resource in <b>/home/zorg1090/public_html/mike/graphic.php3</b> on line <b>47</b><br />
<br />
<b>Warning</b>: imagecolorallocate(): supplied argument is not a valid Image resource in <b>/home/zorg1090/public_html/mike/graphic.php3</b> on line <b>48</b><br />
<br />
<b>Warning</b>: imagecolorallocate(): supplied argument is not a valid Image resource in <b>/home/zorg1090/public_html/mike/graphic.php3</b> on line <b>49</b><br />
<br />
<b>Warning</b>: imagefilledrectangle(): supplied argument is not a valid Image resource in <b>/home/zorg1090/public_html/mike/graphic.php3</b> on line <b>51</b><br />
<br />
<b>Warning</b>: imagesx(): supplied argument is not a valid Image resource in <b>/home/zorg1090/public_html/mike/graphic.php3</b> on line <b>54</b><br />
<br />
<b>Warning</b>: imagestring(): supplied argument is not a valid Image resource in <b>/home/zorg1090/public_html/mike/graphic.php3</b> on line <b>55</b><br />
<br />
<b>Warning</b>: imagepng(): supplied argument is not a valid Image resource in <b>/home/zorg1090/public_html/mike/graphic.php3</b> on line <b>94</b><br />
<br />
<b>Warning</b>: imagedestroy(): supplied argument is not a valid Image resource in <b>/home/zorg1090/public_html/mike/graphic.php3</b> on line <b>96</b><br />





help is very much apreciated

orbitz
06-12-2006, 03:43 PM
$title = urldecode($title);
$data = urldecode($data);


I am not sure where $title and $data come from? are they from a form - POST or GET method?

change it to:

$title = urldecode($_REQUEST['title']);

$data = urldecode($_REQUEST['data']);


try this first. it helps you reduces errors on your script

shockuk
06-12-2006, 03:46 PM
The imagecreate() function requires two integers to be passed, the x and y diamension of the image to be created.

In your script, the imagecreate() function is not working, so the returned handle is not really an editable image. Therefore anything that uses the image handle also doesn't work, and produces lots of warnings :)

You'll need to make sure your $width and $height are being correctly passed to the script.

Try statically setting the variables just before the imagecreate() function to be 100% that incorrect variables are causing the problem:$width = 100;
$height = 100;


It looks to me like the script needs "Register Globals" turned on in php.ini (insecure method!).

orbitz
06-12-2006, 03:49 PM
that's why the problem is from the begining:
$data = urldecode($data); // this gives nothingt to $width and $height

mikey1090
06-13-2006, 03:07 AM
in the link to my image, i pass variable through there....such as img src=graphic.php3?width=200 etc............but if register_globals is off, this wont work...

mikey1090
06-13-2006, 03:13 AM
thanks for the help guys.....seems to be working now:D