Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

So this script stopped working after a server update and I've got no idea why.(updated to php 5)

I can't actually find what's wrong with it, the clues I got suggest that it is a problem around the line 62.

It's a script that calculates biorythm.

    <?php
    $now = gmdate('D, d M Y H:i:s') . ' GMT';
    header('Expires: ' . $now);
    header('Last-Modified: ' . $now);
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Pragma: no-cache");
    error_reporting(0);

    $copyright = "By www.magnaromagna.it";


    $name = $_POST["name"];
    $day = $_POST["day"];
    $month = $_POST["month"];
    $year = $_POST["year"];
    $cycle = $_POST["cycle"];
    $chartsize = $_POST["chartsize"];

    $name = strip_tags($name);
    if($chartsize == "small")
    {
      $chartwidth = 450;
      $chartheight = 252;
      $tablewidth = 500;
    }
    elseif($chartsize == "medium")
    {
      $chartwidth = 625;
      $chartheight = 350;
      $tablewidth = 655;
    }
    else
    {
      $chartwidth = 800;
      $chartheight = 448;
      $tablewidth = 820;
    }


    $date = date("m/d/y");
    function drawRhythm($daysalive, $period, $color)
{
    //$period = $period * 2;
    global $cycle, $image, $chartwidth, $chartheight;


    $centerday = $daysalive - ($cycle / 2);
    $plotscale = ($chartheight - 25) / 2;
    $plotcenter = ($chartheight - 25) / 2;

    // draw the curve
    for($count = 0; $count <= $cycle; $count  )
    {

echo    $date ; 
        $phase = ((($centerday)   $count) % $period) / $period * 2 * pi();
        $y = 1 - sin($phase) * (float)$plotscale   (float)$plotcenter;

        if($count > 0)
        {
            imageLine($image, $oldx, $oldy, $count * $chartwidth / $cycle, $y, $color);
        }
        $oldx = $count * $chartwidth / $cycle;
        $oldy = $y;
      }

}
$data1 = gregorianToJD($month, $day, $year) ;
$data2 = gregorianToJD(date( "m"), date( "d"), date( "Y")) ;
$pastdays = abs($data1 - $data2);
// $pastdays = abs(gregorianToJD($month, $day, $year) - gregorianToJD(date( "m"), date( "d"), date( "Y"))); //

$image = imageCreate($chartwidth, $chartheight);

$colorbackground   = imageColorAllocate($image, 0, 0, 0);
$colorforeground   = imageColorAllocate($image, 255, 255, 255);
$colorgrid         = imageColorAllocate($image, 255, 255, 255);
$colorborder       = imageColorAllocate($image, 175, 175, 175);
$colorcross        = imageColorAllocate($image, 255, 255, 255);
$colorphysical     = imageColorAllocate($image, 0, 0, 255);
$coloremotional    = imageColorAllocate($image, 255, 0, 0);
$colorintellectual = imageColorAllocate($image, 0, 255, 0);
$colorintuitive    = imageColorAllocate($image, 255, 0, 255);
$colorawareness    = imageColorAllocate($image, 255, 125, 0);
$colorspiritual    = imageColorAllocate($image, 0, 255, 255);
$coloraesthetic    = imageColorAllocate($image, 255, 255, 0);

imageFilledRectangle($image, 0, 0, $width - 1, $height - 1, $colorbackground);


$nrsecondsperday = 60 * 60 * 24;
$diagramdate = time() - ($cycle / 2 * $nrsecondsperday)
                 $nrsecondsperday;
$flagcount = 1;
for ($index = 1; $index < $cycle; $index  )
{
    $thisdate = getDate($diagramdate);
    $countCoord = ($chartwidth / $cycle) * $index;


    imageLine($image, $countCoord, $chartheight - 25, $countCoord,
              $chartheight - 20, $colorgrid);

    $flag = $flagcount%2; 

    if($cycle == 60 && $flag == 0)
    {
      imageString($image, 3, $countCoord - 2, $chartheight - 16,
                $thisdate[ "mday"], $colorgrid);
    }
    elseif($cycle != 60)
    {
      imageString($image, 3, $countCoord - 5, $chartheight - 16,
                $thisdate[ "mday"], $colorgrid);
    }
    $flagcount  ;
    $diagramdate  = $nrsecondsperday;
}


imageRectangle($image, 0, 0, $chartwidth - 1, $chartheight - 20,
               $colorborder);

imageLine($image, 0, ($chartheight - 20) / 2, $chartwidth,
          ($chartheight - 20) / 2, $colorcross);
imageLine($image, $chartwidth / 2, 0, $chartwidth / 2, $chartheight - 20,
          $colorcross);

drawRhythm($pastdays, 23, $colorphysical);
drawRhythm($pastdays, 28, $coloremotional);
drawRhythm($pastdays, 33, $colorintellectual);
drawRhythm($pastdays, 38, $colorintuitive);
drawRhythm($pastdays, 43, $coloraesthetic);
drawRhythm($pastdays, 48, $colorawareness);
drawRhythm($pastdays, 53, $colorspiritual);

$subnum = rand(0, 999999);
$subnum = "images/dummies/".$subnum.".gif";
imageGIF($image,$subnum);
imagedestroy($image);
?>

<html>

<head>
<title>Risultato Bioritmo</title>
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<meta name="robots" content="index,follow" />
<link rel="stylesheet" type="text/css" href="biostyle.css">
</head>

<body>
<div align="center"><center>
<table border="0" cellpadding="3" cellspacing="0"  width="<?echo"$tablewidth";?>">
<TR><TD align = "right"><a href="http://www.magnaromagna.it/bioritmo/" target="_blank" class="pagelinks">Calcola altro bioritmo</a>
  </TD></TR></TABLE>
</div>
<div align="center"><center>
<table border="1" cellpadding="7" cellspacing="0"  width="<?echo"$tablewidth";?>" class="outertable">
  <tr>
    <td align="center" class="genericstyle"><p class="bluesubheader">
    <?
       if($name != "")
       {
         echo"Bioritmo per $name<br>";
       }
       else
       {
          echo"Mappa dei tuoi bioritmi<br>";
       }
     ?>

    <?
       echo"Nascita: $month/$day/$year<br>
       Data di oggi: $date";
    ?>
    </p>
    <p align="center"><img src="<?echo"$subnum";?>">
        Rosso: Ciclo Emozionale&nbsp;|&nbsp;
        Blu: Ciclo Fisico&nbsp;|&nbsp;
        Verde: Ciclo Intelligenza <br>
        Viola: Intuito&nbsp;|&nbsp;
        Acqua: Ciclo Spirituale&nbsp;|&nbsp;
        Giallo: Ciclo Estetico&nbsp;|&nbsp;
        Arancione:Ciclo Consapevolezza</p>
    <p align="left"><span class="bluesubheader"><br>
    Capire il tuo bioritmo</span></p>
   </td>
  </tr>
</table>
</center></div>
<div align="center"><center>
<table border="0" cellpadding="3" cellspacing="0"  width="<?echo"$tablewidth";?>">
<TR><TD align = "right"><a href="http://www.magnaromagna.it/bioritmo/" class="pagelinks" target="_blank">Calcola altro bioritmo</a>
  </TD></TR></TABLE>
</div>
<div align="center"><center>

<table border="0" cellpadding="7" cellspacing="0" width="300">
  <tr>
    <td align="center" class="copyright">Copyright Magnaromagna</td>
  </tr>
</table>
    </center></div>
    </body>
    </html>
    <?include("images/dummies/cleanup.php");

    ?>

Any help would be immensely appreciated!

share|improve this question
2  
define "stopped working".. does it throw errors? –  tlenss Jul 23 '13 at 5:57
1  
Are short tags set to ON ? If not, change <?include("images/dummies/cleanup.php"); to <?php include("images/dummies/cleanup.php"); and all <? to <?php. –  Fred -ii- Jul 23 '13 at 5:59
    
it simply doesn't do what it is supposed to. –  user2602145 Jul 23 '13 at 6:01
    
And yes, short tags are on –  user2602145 Jul 23 '13 at 6:02
    
@user2602145 This is the first error I get from testing your code: Parse error: syntax error, unexpected '$count' (T_VARIABLE) in (MY_SERVER/test.php) on line 56. You have pi() in there. I take it that pi() is a function and is not found anywhere in your posted code. –  Fred -ii- Jul 23 '13 at 6:14

2 Answers 2

As I seen you code find that your for loop is here:

for($count = 0; $count <= $cycle; $count  )

It a infinite loop, so make it sensible:

for($count = 0; $count <= $cycle; $count++  ) //use increment or decrements

And other thing is that use are using the sort tag of PHP i.e. <? this will causes the problem and you are not leaving the spaces in that. many servers not support that. So Always use the PHP full tag i.e.

<?php // at each place use it may be your sort tag is not on

always should leave a space after the tag.

Your code:

<?echo"$tablewidth";?>

It should be:

<?php echo "$tablewidth"; ?>

Check all that and your script will work.

share|improve this answer

Morning, not sure if its a typo but in the draw curve section you have 2 variables next to each just seperated by () .. when i quickly ran the script locally it gave me T_variable errors on the following 2 lines..

 $phase = ((($centerday) $count) % $period) / $period * 2 * pi();

should be

 $phase = ((($centerday) * $count) % $period) / $period * 2 * pi();

as that throws an unexpected t_variable error.

Also the line below

 $y = 1 - sin($phase) * (float)$plotscale   (float)$plotcenter;

needs a sepeartor between (float)$plotscale and (float)$plotcenter... else that also throws a T_Variable error...

hopefully that may help.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.