Hi,

I have a code that exceeds the maximum execution time of 60 seconds. I suspect it may be an infinite loop created by accident.

I'm trying to create an online image grid generator, but need some help. You can find it at:

http://www.johninteractive.net/dynamic-images/grid.html

Here is the code:

<?php
$image = imagecreate($_GET['width'], $_GET['height']);
$color = imagecolorallocate($image, $_GET['color1'], $_GET['color2'], $_GET['color3']);
$color2 = imagecolorallocate($image, $_GET['color4'], $_GET['color5'], $_GET['color6']);
$widthspacing = $_GET['widthspacing'];
for ($i = 0; $i <= $width; $i += $widthspacing) {
imageline($image, $i, 0, $i, 255, $color2);
}
$heightspacing = $_GET['heightspacing'];
for ($i = 0; $i <= $height; $i += $heightspacing) {
imageline($image, 0, $i, 255, $i, $color2);
}
header("Content-type: image/png");
imagepng($image);
imagedestroy($image);
?>

However, when I replace the $widthspacing and $heightspacing variables with any number, it works okay! Even when I entered a numerical value submitted from the form for $heightspacing and $widthspacing, it didn't work. Why is this?

Also, if I DID enter it with a number, I see two unwanted lines at the bottom seperate from the grid. Why is this?

Thanks.

    In the source of your form, you misnamed your variable...

    <input type="text" name="heighspacing" value="Height Spacing"><br>

    Should be:

    <input type="text" name="heightspacing" value="Height Spacing"><br>

      This is a lesson to learn, nonetheless: check that any incoming variables you use exist and validate them.

      For example:

      if (isset($_GET['widthspacing'], $_GET['heightspacing'])) {
          $widthspacing = (int)$_GET['widthspacing'];
          $heightspacing = (int)$_GET['heightspacing'];
          if ($widthspacing > 0 && $heightspacing > 0) {
              // Create the PNG.
          }
      }

      Of course, you have other incoming variables that need to be checked as well.

        Sorry, my fault for making that silly mistake. But does anybody know why when you type some values in, a few lines appear extra on apart from the grid? Same coding as before.

          Write a Reply...